From e9a7455e81b1867c48672bed4417d55cd93f179f Mon Sep 17 00:00:00 2001 From: vincentarnaud90 <37067128+vincentarnaud90@users.noreply.github.com> Date: Wed, 28 Aug 2019 16:02:56 +0200 Subject: [PATCH] Code formating Revert changes from codestyle and generate data in CommandTest with loops --- .../hadoop/rest/InitializationUtils.java | 5 +- .../serialization/bulk/DeleteBulkFactory.java | 52 +++++----- .../hadoop/serialization/CommandTest.java | 94 +++++++------------ 3 files changed, 60 insertions(+), 91 deletions(-) diff --git a/mr/src/main/java/org/elasticsearch/hadoop/rest/InitializationUtils.java b/mr/src/main/java/org/elasticsearch/hadoop/rest/InitializationUtils.java index f08a21d1a..08718dfe7 100644 --- a/mr/src/main/java/org/elasticsearch/hadoop/rest/InitializationUtils.java +++ b/mr/src/main/java/org/elasticsearch/hadoop/rest/InitializationUtils.java @@ -299,8 +299,7 @@ public static void validateSettingsForWriting(Settings settings) { throw new EsHadoopIllegalArgumentException("Cannot use TTL on index/update requests in ES 6.x and " + "above. Please remove the [" + ConfigurationOptions.ES_MAPPING_TTL + "] setting."); } - } - else { + } else { if (StringUtils.hasText(settings.getMappingTtl())) { LOG.warn("Setting [" + ConfigurationOptions.ES_MAPPING_TTL + "] is deprecated! Support for [ttl] on " + "indexing and update requests has been removed in ES 6.x and above!"); @@ -387,7 +386,7 @@ private static void doCheckIndexExistence(Settings settings, RestRepository clie settings.getResourceWrite(), ConfigurationOptions.ES_INDEX_AUTO_CREATE, settings.getIndexAutoCreate())); } } - + public static boolean setMetadataExtractorIfNotSet(Settings settings, Class clazz, Log log) { if (!StringUtils.hasText(settings.getMappingMetadataExtractorClassName())) { Log logger = (log != null ? log : LogFactory.getLog(clazz)); diff --git a/mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/DeleteBulkFactory.java b/mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/DeleteBulkFactory.java index 9c65f3f6d..fc0d9a049 100644 --- a/mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/DeleteBulkFactory.java +++ b/mr/src/main/java/org/elasticsearch/hadoop/serialization/bulk/DeleteBulkFactory.java @@ -18,7 +18,19 @@ */ package org.elasticsearch.hadoop.serialization.bulk; -import org.apache.hadoop.io.*; +import org.apache.hadoop.io.BooleanWritable; +import org.apache.hadoop.io.ByteWritable; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.MD5Hash; +import org.apache.hadoop.io.NullWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.UTF8; +import org.apache.hadoop.io.VIntWritable; +import org.apache.hadoop.io.VLongWritable; import org.elasticsearch.hadoop.cfg.ConfigurationOptions; import org.elasticsearch.hadoop.cfg.Settings; import org.elasticsearch.hadoop.serialization.Generator; @@ -34,47 +46,35 @@ public static final class NoDataWriter implements ValueWriter { @Override public Result write(Object writable, Generator generator) { - ///delete doesn't require any content but it needs to extract metadata associated to a document + //delete doesn't require any content but it needs to extract metadata associated to a document if (writable == null || writable instanceof NullWritable) { generator.writeNull(); - } - else if (writable instanceof Text) { + } else if (writable instanceof Text) { Text text = (Text) writable; generator.writeUTF8String(text.getBytes(), 0, text.getLength()); - } - else if (writable instanceof UTF8) { + } else if (writable instanceof UTF8) { UTF8 utf8 = (UTF8) writable; generator.writeUTF8String(utf8.getBytes(), 0, utf8.getLength()); - } - else if (writable instanceof IntWritable) { + } else if (writable instanceof IntWritable) { generator.writeNumber(((IntWritable) writable).get()); - } - else if (writable instanceof LongWritable) { + } else if (writable instanceof LongWritable) { generator.writeNumber(((LongWritable) writable).get()); - } - else if (writable instanceof VLongWritable) { + } else if (writable instanceof VLongWritable) { generator.writeNumber(((VLongWritable) writable).get()); - } - else if (writable instanceof VIntWritable) { + } else if (writable instanceof VIntWritable) { generator.writeNumber(((VIntWritable) writable).get()); - } - else if (writable instanceof ByteWritable) { + } else if (writable instanceof ByteWritable) { generator.writeNumber(((ByteWritable) writable).get()); - } - else if (writable instanceof DoubleWritable) { + } else if (writable instanceof DoubleWritable) { generator.writeNumber(((DoubleWritable) writable).get()); - } - else if (writable instanceof FloatWritable) { + } else if (writable instanceof FloatWritable) { generator.writeNumber(((FloatWritable) writable).get()); - } - else if (writable instanceof BooleanWritable) { + } else if (writable instanceof BooleanWritable) { generator.writeBoolean(((BooleanWritable) writable).get()); - } - else if (writable instanceof BytesWritable) { + } else if (writable instanceof BytesWritable) { BytesWritable bw = (BytesWritable) writable; generator.writeBinary(bw.getBytes(), 0, bw.getLength()); - } - else if (writable instanceof MD5Hash) { + } else if (writable instanceof MD5Hash) { generator.writeString(writable.toString()); } return Result.SUCCESFUL(); diff --git a/mr/src/test/java/org/elasticsearch/hadoop/serialization/CommandTest.java b/mr/src/test/java/org/elasticsearch/hadoop/serialization/CommandTest.java index 311eb0251..abf5c18cf 100644 --- a/mr/src/test/java/org/elasticsearch/hadoop/serialization/CommandTest.java +++ b/mr/src/test/java/org/elasticsearch/hadoop/serialization/CommandTest.java @@ -18,8 +18,10 @@ */ package org.elasticsearch.hadoop.serialization; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -65,56 +67,29 @@ public static Collection data() { throw new IllegalStateException("CommandTest needs new version updates."); } - return Arrays.asList(new Object[][]{ - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_1_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_2_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_5_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_6_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_7_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, false, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, false, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, false, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, false, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_INDEX, true, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_CREATE, true, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_UPDATE, true, EsMajorVersion.V_8_X}, - {ConfigurationOptions.ES_OPERATION_DELETE, true, EsMajorVersion.V_8_X} - }); + Collection result = new ArrayList<>(); + + String[] operations = new String[]{ConfigurationOptions.ES_OPERATION_INDEX, + ConfigurationOptions.ES_OPERATION_CREATE, + ConfigurationOptions.ES_OPERATION_UPDATE, + ConfigurationOptions.ES_OPERATION_DELETE}; + boolean[] asJsons = new boolean[]{false, true}; + EsMajorVersion[] versions = new EsMajorVersion[]{EsMajorVersion.V_1_X, + EsMajorVersion.V_2_X, + EsMajorVersion.V_5_X, + EsMajorVersion.V_6_X, + EsMajorVersion.V_7_X, + EsMajorVersion.V_8_X}; + + for (EsMajorVersion version : versions) { + for (boolean asJson : asJsons) { + for (String operation : operations) { + result.add(new Object[]{ operation, asJson, version }); + } + } + } + + return result; } public CommandTest(String operation, boolean jsonInput, EsMajorVersion version) { @@ -131,8 +106,7 @@ public void prepare() { map.put("n", 1); map.put("s", "v"); data = map; - } - else { + } else { data = "{\"n\":1,\"s\":\"v\"}"; } } @@ -287,8 +261,7 @@ public void testIdPattern() throws Exception { Settings settings = settings(); if (version.onOrAfter(EsMajorVersion.V_8_X)) { settings.setResourceWrite("{n}"); - } - else { + } else { settings.setResourceWrite("foo/{n}"); } @@ -296,8 +269,7 @@ public void testIdPattern() throws Exception { String header; if (version.onOrAfter(EsMajorVersion.V_8_X)) { header = "{\"_index\":\"1\"" + (isUpdateOp() ? ",\"_id\":2" : "") + "}"; - } - else { + } else { header = "{\"_index\":\"foo\",\"_type\":\"1\"" + (isUpdateOp() ? ",\"_id\":2" : "") + "}"; } String result = "{\"" + operation + "\":" + header + "}" + map(); @@ -345,7 +317,7 @@ public void testUpdateOnlyInlineScript5X() throws Exception { create(set).write(data).copyTo(ba); String result = "{\"" + operation + "\":{\"_id\":2,\"_retry_on_conflict\":3}}\n" + - "{\"script\":{\"inline\":\"counter = 3\",\"lang\":\"groovy\"}}\n"; + "{\"script\":{\"inline\":\"counter = 3\",\"lang\":\"groovy\"}}\n"; assertEquals(result, ba.toString()); } @@ -475,7 +447,7 @@ public void testUpdateOnlyParamInlineScript5X() throws Exception { String result = "{\"" + operation + "\":{\"_id\":1}}\n" + - "{\"script\":{\"inline\":\"counter = param1; anothercounter = param2\",\"lang\":\"groovy\",\"params\":{\"param1\":1,\"param2\":1}}}\n"; + "{\"script\":{\"inline\":\"counter = param1; anothercounter = param2\",\"lang\":\"groovy\",\"params\":{\"param1\":1,\"param2\":1}}}\n"; assertEquals(result, ba.toString()); } @@ -553,8 +525,7 @@ private Settings settings() { set.setProperty(ConfigurationOptions.ES_INPUT_JSON, Boolean.toString(jsonInput)); if (isDeleteOP()) { InitializationUtils.setValueWriterIfNotSet(set, DeleteBulkFactory.NoDataWriter.class, null); - } - else { + } else { InitializationUtils.setValueWriterIfNotSet(set, JdkValueWriter.class, null); } InitializationUtils.setFieldExtractorIfNotSet(set, MapFieldExtractor.class, null); @@ -564,8 +535,7 @@ private Settings settings() { set.setProperty(ConfigurationOptions.ES_WRITE_OPERATION, operation); if (version.onOrAfter(EsMajorVersion.V_8_X)) { set.setResourceWrite("foo"); - } - else { + } else { set.setResourceWrite("foo/bar"); } if (isUpdateOp()) {