Finish removing ImmutableMap#of from tests

This commit is contained in:
Nik Everett 2015-10-02 02:44:28 +02:00
parent f68dabe615
commit e75f1137f2
10 changed files with 113 additions and 61 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.cluster.node; package org.elasticsearch.cluster.node;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.transport.DummyTransportAddress;
@ -35,6 +36,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND; import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR; import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -62,10 +65,10 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build(); .build();
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -76,10 +79,10 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build(); .build();
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -91,13 +94,13 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); node = new DiscoveryNode("name2", "id2", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
node = new DiscoveryNode("name3", "id3", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); node = new DiscoveryNode("name3", "id3", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -121,7 +124,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
ImmutableMap.of("tag", "A", "group", "F", "name", "X"), Version.CURRENT); ImmutableMap.of("tag", "A", "group", "F", "name", "X"), Version.CURRENT);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
node = new DiscoveryNode("name4", "id4", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); node = new DiscoveryNode("name4", "id4", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -132,7 +135,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build(); .build();
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode node = new DiscoveryNode("name1", "id1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -144,7 +147,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -156,7 +159,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -168,7 +171,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -180,7 +183,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -192,7 +195,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -204,7 +207,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -216,7 +219,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(false)); assertThat(filters.match(node), equalTo(false));
} }
@ -228,7 +231,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
@ -240,7 +243,7 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
.build()); .build());
DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings); DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, ImmutableMap.of("tag", "A"), null); DiscoveryNode node = new DiscoveryNode("", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), null);
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }

View File

@ -19,15 +19,14 @@
package org.elasticsearch.cluster.routing.allocation; package org.elasticsearch.cluster.routing.allocation;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -36,6 +35,7 @@ import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.test.ESAllocationTestCase; import org.elasticsearch.test.ESAllocationTestCase;
import org.junit.Test; import org.junit.Test;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingNodesUtils.numberOfShardsOfType; import static org.elasticsearch.cluster.routing.allocation.RoutingNodesUtils.numberOfShardsOfType;
import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.common.settings.Settings.settingsBuilder;
@ -62,8 +62,8 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
logger.info("--> adding two nodes with the same host"); logger.info("--> adding two nodes with the same host");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
.put(new DiscoveryNode("node1", "node1", "test1", "test1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT)) .put(new DiscoveryNode("node1", "node1", "test1", "test1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT))
.put(new DiscoveryNode("node2", "node2", "test1", "test1", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT))).build(); .put(new DiscoveryNode("node2", "node2", "test1", "test1", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT))).build();
routingTable = strategy.reroute(clusterState).routingTable(); routingTable = strategy.reroute(clusterState).routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
@ -78,7 +78,7 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
logger.info("--> add another node, with a different host, replicas will be allocating"); logger.info("--> add another node, with a different host, replicas will be allocating");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()) clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.put(new DiscoveryNode("node3", "node3", "test2", "test2", DummyTransportAddress.INSTANCE, ImmutableMap.<String, String>of(), Version.CURRENT))).build(); .put(new DiscoveryNode("node3", "node3", "test2", "test2", DummyTransportAddress.INSTANCE, emptyMap(), Version.CURRENT))).build();
routingTable = strategy.reroute(clusterState).routingTable(); routingTable = strategy.reroute(clusterState).routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

View File

@ -19,12 +19,13 @@
package org.elasticsearch.common.collect; package org.elasticsearch.common.collect;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap;
public class CopyOnWriteHashMapTests extends ESTestCase { public class CopyOnWriteHashMapTests extends ESTestCase {
private static class O { private static class O {
@ -94,7 +95,7 @@ public class CopyOnWriteHashMapTests extends ESTestCase {
map = newMap; map = newMap;
} }
assertEquals(ref, CopyOnWriteHashMap.copyOf(ref)); assertEquals(ref, CopyOnWriteHashMap.copyOf(ref));
assertEquals(ImmutableMap.of(), CopyOnWriteHashMap.copyOf(ref).copyAndRemoveAll(ref.keySet())); assertEquals(emptyMap(), CopyOnWriteHashMap.copyOf(ref).copyAndRemoveAll(ref.keySet()));
} }
} }
@ -140,7 +141,7 @@ public class CopyOnWriteHashMapTests extends ESTestCase {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// expected // expected
} }
try { try {
new CopyOnWriteHashMap<>().copyAndPut(null, "b"); new CopyOnWriteHashMap<>().copyAndPut(null, "b");
fail(); fail();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.discovery; package org.elasticsearch.discovery;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
@ -45,6 +44,7 @@ import org.junit.Test;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class ZenFaultDetectionTests extends ESTestCase { public class ZenFaultDetectionTests extends ESTestCase {
@ -65,9 +65,9 @@ public class ZenFaultDetectionTests extends ESTestCase {
super.setUp(); super.setUp();
threadPool = new ThreadPool(getClass().getName()); threadPool = new ThreadPool(getClass().getName());
serviceA = build(Settings.builder().put("name", "TS_A").build(), version0); serviceA = build(Settings.builder().put("name", "TS_A").build(), version0);
nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version0); nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), emptyMap(), version0);
serviceB = build(Settings.builder().put("name", "TS_B").build(), version1); serviceB = build(Settings.builder().put("name", "TS_B").build(), version1);
nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version1); nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), version1);
// wait till all nodes are properly connected and the event has been sent, so tests in this class // wait till all nodes are properly connected and the event has been sent, so tests in this class
// will not get this callback called on the connections done in this setup // will not get this callback called on the connections done in this setup

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.engine; package org.elasticsearch.index.engine;
import com.google.common.collect.ImmutableMap;
import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
@ -29,7 +28,16 @@ import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.TextField; import org.apache.lucene.document.TextField;
import org.apache.lucene.index.*; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy;
import org.apache.lucene.index.LiveIndexWriterConfig;
import org.apache.lucene.index.LogByteSizeMergePolicy;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.SnapshotDeletionPolicy;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TieredMergePolicy;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
@ -61,9 +69,17 @@ import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.engine.Engine.Searcher; import org.elasticsearch.index.engine.Engine.Searcher;
import org.elasticsearch.index.indexing.ShardIndexingService; import org.elasticsearch.index.indexing.ShardIndexingService;
import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperForType;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.Mapper.BuilderContext; import org.elasticsearch.index.mapper.Mapper.BuilderContext;
import org.elasticsearch.index.mapper.MapperBuilders;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ParseContext.Document; import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper; import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.mapper.object.RootObjectMapper; import org.elasticsearch.index.mapper.object.RootObjectMapper;
@ -92,7 +108,13 @@ import java.nio.charset.Charset;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
@ -101,10 +123,16 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY; import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY;
import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA; import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
public class InternalEngineTests extends ESTestCase { public class InternalEngineTests extends ESTestCase {
@ -1021,6 +1049,7 @@ public class InternalEngineTests extends ESTestCase {
final CountDownLatch indexed = new CountDownLatch(1); final CountDownLatch indexed = new CountDownLatch(1);
Thread thread = new Thread() { Thread thread = new Thread() {
@Override
public void run() { public void run() {
try { try {
try { try {
@ -1689,7 +1718,7 @@ public class InternalEngineTests extends ESTestCase {
private Mapping dynamicUpdate() { private Mapping dynamicUpdate() {
BuilderContext context = new BuilderContext(Settings.EMPTY, new ContentPath()); BuilderContext context = new BuilderContext(Settings.EMPTY, new ContentPath());
final RootObjectMapper root = MapperBuilders.rootObject("some_type").build(context); final RootObjectMapper root = MapperBuilders.rootObject("some_type").build(context);
return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], new Mapping.SourceTransform[0], ImmutableMap.<String, Object>of()); return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], new Mapping.SourceTransform[0], emptyMap());
} }
public void testUpgradeOldIndex() throws IOException { public void testUpgradeOldIndex() throws IOException {

View File

@ -18,12 +18,15 @@
*/ */
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.*; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.core.IntegerFieldMapper; import org.elasticsearch.index.mapper.core.IntegerFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper; import org.elasticsearch.index.mapper.core.StringFieldMapper;
@ -31,6 +34,7 @@ import org.elasticsearch.test.ESSingleNodeTestCase;
import java.io.IOException; import java.io.IOException;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
@ -186,7 +190,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
private String serialize(ToXContent mapper) throws Exception { private String serialize(ToXContent mapper) throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
mapper.toXContent(builder, new ToXContent.MapParams(ImmutableMap.<String, String>of())); mapper.toXContent(builder, new ToXContent.MapParams(emptyMap()));
return builder.endObject().string(); return builder.endObject().string();
} }
@ -321,7 +325,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties")
.startObject("foo").field("type", "object").endObject() .startObject("foo").field("type", "object").endObject()
.endObject().endObject().endObject().string(); .endObject().endObject().endObject().string();
DocumentMapper mapper = parser.parse(mapping); DocumentMapper mapper = parser.parse(mapping);
assertEquals(mapping, serialize(mapper)); assertEquals(mapping, serialize(mapper));

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.mapper.string; package org.elasticsearch.index.mapper.string;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableField;
@ -44,6 +43,7 @@ import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext.Document; import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.core.StringFieldMapper; import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper.Builder;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.VersionUtils;
import org.junit.Before; import org.junit.Before;
@ -52,8 +52,11 @@ import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.index.mapper.core.StringFieldMapper.Builder; import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/** /**
*/ */
@ -121,7 +124,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
} }
private void assertParseIdemPotent(IndexableFieldType expected, DocumentMapper mapper) throws Exception { private void assertParseIdemPotent(IndexableFieldType expected, DocumentMapper mapper) throws Exception {
String mapping = mapper.toXContent(XContentFactory.jsonBuilder().startObject(), new ToXContent.MapParams(ImmutableMap.<String, String>of())).endObject().string(); String mapping = mapper.toXContent(XContentFactory.jsonBuilder().startObject(), new ToXContent.MapParams(emptyMap())).endObject().string();
mapper = parser.parse(mapping); mapper = parser.parse(mapping);
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder() ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
.startObject() .startObject()
@ -214,7 +217,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
assertThat(fieldType.omitNorms(), equalTo(false)); assertThat(fieldType.omitNorms(), equalTo(false));
assertParseIdemPotent(fieldType, defaultMapper); assertParseIdemPotent(fieldType, defaultMapper);
} }
@Test @Test
public void testSearchQuoteAnalyzerSerialization() throws Exception { public void testSearchQuoteAnalyzerSerialization() throws Exception {
// Cases where search_quote_analyzer should not be added to the mapping. // Cases where search_quote_analyzer should not be added to the mapping.
@ -250,7 +253,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
Map<String, Object> serializedMap = getSerializedMap(fieldName, mapper); Map<String, Object> serializedMap = getSerializedMap(fieldName, mapper);
assertFalse(fieldName, serializedMap.containsKey("search_quote_analyzer")); assertFalse(fieldName, serializedMap.containsKey("search_quote_analyzer"));
} }
// Cases where search_quote_analyzer should be present. // Cases where search_quote_analyzer should be present.
mapping = XContentFactory.jsonBuilder().startObject().startObject("type") mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties") .startObject("properties")
@ -268,20 +271,20 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
.endObject() .endObject()
.endObject() .endObject()
.endObject().endObject().string(); .endObject().endObject().string();
mapper = parser.parse(mapping); mapper = parser.parse(mapping);
for (String fieldName : Arrays.asList("field1", "field2")) { for (String fieldName : Arrays.asList("field1", "field2")) {
Map<String, Object> serializedMap = getSerializedMap(fieldName, mapper); Map<String, Object> serializedMap = getSerializedMap(fieldName, mapper);
assertEquals(serializedMap.get("search_quote_analyzer"), "simple"); assertEquals(serializedMap.get("search_quote_analyzer"), "simple");
} }
} }
private Map<String, Object> getSerializedMap(String fieldName, DocumentMapper mapper) throws Exception { private Map<String, Object> getSerializedMap(String fieldName, DocumentMapper mapper) throws Exception {
FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper(fieldName); FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper(fieldName);
XContentBuilder builder = JsonXContent.contentBuilder().startObject(); XContentBuilder builder = JsonXContent.contentBuilder().startObject();
fieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject(); fieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();
builder.close(); builder.close();
Map<String, Object> fieldMap; Map<String, Object> fieldMap;
try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes())) { try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes())) {
fieldMap = parser.map(); fieldMap = parser.map();
@ -464,7 +467,7 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
assertEquals(DocValuesType.NONE, docValuesType(doc, "str3")); assertEquals(DocValuesType.NONE, docValuesType(doc, "str3"));
assertEquals(DocValuesType.NONE, docValuesType(doc, "str4")); assertEquals(DocValuesType.NONE, docValuesType(doc, "str4"));
assertEquals(DocValuesType.SORTED_SET, docValuesType(doc, "str5")); assertEquals(DocValuesType.SORTED_SET, docValuesType(doc, "str5"));
} }
// TODO: this function shouldn't be necessary. parsing should just add a single field that is indexed and dv // TODO: this function shouldn't be necessary. parsing should just add a single field that is indexed and dv

View File

@ -37,6 +37,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
@ -92,12 +94,12 @@ public class ExistsMissingIT extends ESIntegTestCase {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Map<String, Object>[] sources = new Map[] { final Map<String, Object>[] sources = new Map[] {
// simple property // simple property
ImmutableMap.of("foo", "bar"), singletonMap("foo", "bar"),
// object fields // object fields
ImmutableMap.of("bar", ImmutableMap.of("foo", "bar", "bar", ImmutableMap.of("bar", "foo"))), singletonMap("bar", ImmutableMap.of("foo", "bar", "bar", singletonMap("bar", "foo"))),
ImmutableMap.of("bar", ImmutableMap.of("baz", 42)), singletonMap("bar", singletonMap("baz", 42)),
// empty doc // empty doc
ImmutableMap.of() emptyMap()
}; };
List<IndexRequestBuilder> reqs = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> reqs = new ArrayList<IndexRequestBuilder>();
for (Map<String, Object> source : sources) { for (Map<String, Object> source : sources) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.transport; package org.elasticsearch.transport;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@ -42,8 +41,12 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.transport.TransportRequestOptions.options; import static org.elasticsearch.transport.TransportRequestOptions.options;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
/** /**
* *
@ -71,12 +74,12 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
Settings.builder().put("name", "TS_A", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(), Settings.builder().put("name", "TS_A", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
version0, new NamedWriteableRegistry() version0, new NamedWriteableRegistry()
); );
nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version0); nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), emptyMap(), version0);
serviceB = build( serviceB = build(
Settings.builder().put("name", "TS_B", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(), Settings.builder().put("name", "TS_B", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
version1, new NamedWriteableRegistry() version1, new NamedWriteableRegistry()
); );
nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version1); nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), version1);
// wait till all nodes are properly connected and the event has been sent, so tests in this class // wait till all nodes are properly connected and the event has been sent, so tests in this class
// will not get this callback called on the connections done in this setup // will not get this callback called on the connections done in this setup

View File

@ -18,7 +18,6 @@
*/ */
package org.elasticsearch.transport.netty; package org.elasticsearch.transport.netty;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@ -29,11 +28,19 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*; import org.elasticsearch.transport.BaseTransportResponseHandler;
import org.elasticsearch.transport.TransportChannel;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequest;
import org.elasticsearch.transport.TransportRequestHandler;
import org.elasticsearch.transport.TransportRequestOptions;
import org.elasticsearch.transport.TransportResponse;
import org.elasticsearch.transport.TransportResponseOptions;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
@ -57,8 +64,8 @@ public class NettyScheduledPingTests extends ESTestCase {
MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool); MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool);
serviceB.start(); serviceB.start();
DiscoveryNode nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), emptyMap(), Version.CURRENT);
DiscoveryNode nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), Version.CURRENT); DiscoveryNode nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), Version.CURRENT);
serviceA.connectToNode(nodeB); serviceA.connectToNode(nodeB);
serviceB.connectToNode(nodeA); serviceB.connectToNode(nodeA);