use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class RoutingTest method testRoutingForRandomMasterOrDataNodePrefersLocal.
@Test
public void testRoutingForRandomMasterOrDataNodePrefersLocal() throws Exception {
Set<DiscoveryNodeRole> data = Set.of(DiscoveryNodeRole.DATA_ROLE);
Map<String, String> attr = Map.of();
DiscoveryNode local = new DiscoveryNode("local_data", buildNewFakeTransportAddress(), attr, data, null);
DiscoveryNodes nodes = new DiscoveryNodes.Builder().add(local).localNodeId(local.getId()).add(new DiscoveryNode("data_1", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_2", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_3", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_4", buildNewFakeTransportAddress(), attr, data, null)).build();
RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList());
Routing routing = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
assertThat(routing.locations().keySet(), contains("local_data"));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class RoutingTest method testRoutingForRandomMasterOrDataNode.
@Test
public void testRoutingForRandomMasterOrDataNode() throws IOException {
Map<String, String> attr = Map.of();
Set<DiscoveryNodeRole> master_and_data = Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE);
DiscoveryNode local = new DiscoveryNode("client_node_1", buildNewFakeTransportAddress(), attr, Set.of(), null);
DiscoveryNodes nodes = new DiscoveryNodes.Builder().add(new DiscoveryNode("data_master_node_1", buildNewFakeTransportAddress(), attr, master_and_data, null)).add(new DiscoveryNode("data_master_node_2", buildNewFakeTransportAddress(), attr, master_and_data, null)).add(local).add(new DiscoveryNode("client_node_2", buildNewFakeTransportAddress(), attr, Set.of(), null)).add(new DiscoveryNode("client_node_3", buildNewFakeTransportAddress(), attr, Set.of(), null)).localNodeId(local.getId()).build();
RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList());
Routing routing = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
assertThat(routing.locations().keySet(), anyOf(contains("data_master_node_1"), contains("data_master_node_2")));
Routing routing2 = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
assertThat("routingProvider is seeded and must return deterministic routing", routing.locations(), equalTo(routing2.locations()));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class AsyncShardFetchTests method testIgnoreFailureFromDifferentRound.
public void testIgnoreFailureFromDifferentRound() throws Exception {
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
// add a failed response for node1
test.addSimulation(node1.getId(), failure1);
// first fetch, no data, still on going
AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(false));
assertThat(test.reroute.get(), equalTo(0));
// handle a failure with incorrect round id, wait on reroute incrementing
test.processAsyncFetch(Collections.emptyList(), Collections.singletonList(new FailedNodeException(node1.getId(), "dummy failure", failure1)), 0);
assertThat(fetchData.hasData(), equalTo(false));
assertThat(test.reroute.get(), equalTo(1));
// fire a response, wait on reroute incrementing
test.fireSimulationAndWait(node1.getId());
// failure, fetched data exists, but has no data
assertThat(test.reroute.get(), equalTo(2));
fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(true));
assertThat(fetchData.getData().size(), equalTo(0));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class AsyncShardFetchTests method testConcurrentRequestAndClearCache.
public void testConcurrentRequestAndClearCache() throws Exception {
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
test.addSimulation(node1.getId(), response1);
// no fetched data, request still on going
AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(false));
assertThat(test.reroute.get(), equalTo(0));
// clear cache while request is still on going, before it is processed
test.clearCacheForNode(node1.getId());
test.fireSimulationAndWait(node1.getId());
assertThat(test.reroute.get(), equalTo(1));
// prepare next request
test.addSimulation(node1.getId(), response1_2);
// verify still no fetched data, request still on going
fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(false));
test.fireSimulationAndWait(node1.getId());
assertThat(test.reroute.get(), equalTo(2));
// verify we get new data back
fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(true));
assertThat(fetchData.getData().size(), equalTo(1));
assertThat(fetchData.getData().get(node1), sameInstance(response1_2));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class AsyncShardFetchTests method testIgnoreResponseFromDifferentRound.
public void testIgnoreResponseFromDifferentRound() throws Exception {
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
test.addSimulation(node1.getId(), response1);
// first fetch, no data, still on going
AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(false));
assertThat(test.reroute.get(), equalTo(0));
// handle a response with incorrect round id, wait on reroute incrementing
test.processAsyncFetch(Collections.singletonList(response1), Collections.emptyList(), 0);
assertThat(fetchData.hasData(), equalTo(false));
assertThat(test.reroute.get(), equalTo(1));
// fire a response (with correct round id), wait on reroute incrementing
test.fireSimulationAndWait(node1.getId());
// verify we get back the data node
assertThat(test.reroute.get(), equalTo(2));
fetchData = test.fetchData(nodes, emptySet());
assertThat(fetchData.hasData(), equalTo(true));
assertThat(fetchData.getData().size(), equalTo(1));
assertThat(fetchData.getData().get(node1), sameInstance(response1));
}
Aggregations