Skip to content

Commit

Permalink
Code formating
Browse files Browse the repository at this point in the history
Revert changes from codestyle and generate data in CommandTest with loops
  • Loading branch information
vincentarnaud90 authored Aug 28, 2019
1 parent 2bccf4a commit e9a7455
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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<? extends MetadataExtractor> clazz, Log log) {
if (!StringUtils.hasText(settings.getMappingMetadataExtractorClassName())) {
Log logger = (log != null ? log : LogFactory.getLog(clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,47 +46,35 @@ public static final class NoDataWriter implements ValueWriter<Object> {

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -65,56 +67,29 @@ public static Collection<Object[]> 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<Object[]> 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) {
Expand All @@ -131,8 +106,7 @@ public void prepare() {
map.put("n", 1);
map.put("s", "v");
data = map;
}
else {
} else {
data = "{\"n\":1,\"s\":\"v\"}";
}
}
Expand Down Expand Up @@ -287,17 +261,15 @@ public void testIdPattern() throws Exception {
Settings settings = settings();
if (version.onOrAfter(EsMajorVersion.V_8_X)) {
settings.setResourceWrite("{n}");
}
else {
} else {
settings.setResourceWrite("foo/{n}");
}

create(settings).write(data).copyTo(ba);
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();
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down

0 comments on commit e9a7455

Please sign in to comment.