use of org.elasticsearch.test.transport.MockTransportService in project crate by crate.
the class SrvUnicastHostsProviderTest method mockTransportService.
@Before
public void mockTransportService() throws Exception {
String localHostName = InetAddress.getLocalHost().getCanonicalHostName();
isLocalHost = anyOf(is(localHostName), is("localhost"));
threadPool = new TestThreadPool("dummy", Settings.EMPTY);
TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null);
srvUnicastHostsProvider = new SrvUnicastHostsProvider(Settings.EMPTY, transportService);
}
use of org.elasticsearch.test.transport.MockTransportService in project crate by crate.
the class DiscoveryDisruptionIT method testNodeNotReachableFromMaster.
/**
* Adds an asymmetric break between a master and one of the nodes and makes
* sure that the node is removed form the cluster, that the node start pinging and that
* the cluster reforms when healed.
*/
@Test
public void testNodeNotReachableFromMaster() throws Exception {
startCluster(3);
String masterNode = internalCluster().getMasterName();
String nonMasterNode = null;
while (nonMasterNode == null) {
nonMasterNode = randomFrom(internalCluster().getNodeNames());
if (nonMasterNode.equals(masterNode)) {
nonMasterNode = null;
}
}
logger.info("blocking request from master [{}] to [{}]", masterNode, nonMasterNode);
MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
if (randomBoolean()) {
masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
} else {
masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
}
logger.info("waiting for [{}] to be removed from cluster", nonMasterNode);
ensureStableCluster(2, masterNode);
logger.info("waiting for [{}] to have no master", nonMasterNode);
assertNoMaster(nonMasterNode);
logger.info("healing partition and checking cluster reforms");
masterTransportService.clearAllRules();
ensureStableCluster(3);
}
use of org.elasticsearch.test.transport.MockTransportService in project crate by crate.
the class DiscoveryDisruptionIT method testClusterJoinDespiteOfPublishingIssues.
/**
* Test cluster join with issues in cluster state publishing *
*/
@Test
public void testClusterJoinDespiteOfPublishingIssues() throws Exception {
String masterNode = internalCluster().startMasterOnlyNode();
String nonMasterNode = internalCluster().startDataOnlyNode();
DiscoveryNodes discoveryNodes = internalCluster().getInstance(ClusterService.class, nonMasterNode).state().nodes();
TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.getMasterNode().getName());
logger.info("blocking requests from non master [{}] to master [{}]", nonMasterNode, masterNode);
MockTransportService nonMasterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nonMasterNode);
nonMasterTransportService.addFailToSendNoConnectRule(masterTranspotService);
assertNoMaster(nonMasterNode);
logger.info("blocking cluster state publishing from master [{}] to non master [{}]", masterNode, nonMasterNode);
MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
TransportService localTransportService = internalCluster().getInstance(TransportService.class, discoveryNodes.getLocalNode().getName());
if (randomBoolean()) {
masterTransportService.addFailToSendNoConnectRule(localTransportService, PublicationTransportHandler.PUBLISH_STATE_ACTION_NAME);
} else {
masterTransportService.addFailToSendNoConnectRule(localTransportService, PublicationTransportHandler.COMMIT_STATE_ACTION_NAME);
}
logger.info("allowing requests from non master [{}] to master [{}], waiting for two join request", nonMasterNode, masterNode);
final CountDownLatch countDownLatch = new CountDownLatch(2);
nonMasterTransportService.addSendBehavior(masterTransportService, (connection, requestId, action, request, options) -> {
if (action.equals(JoinHelper.JOIN_ACTION_NAME)) {
countDownLatch.countDown();
}
connection.sendRequest(requestId, action, request, options);
});
nonMasterTransportService.addConnectBehavior(masterTransportService, Transport::openConnection);
countDownLatch.await();
logger.info("waiting for cluster to reform");
masterTransportService.clearOutboundRules(localTransportService);
nonMasterTransportService.clearOutboundRules(localTransportService);
ensureStableCluster(2);
// shutting down the nodes, to avoid the leakage check tripping
// on the states associated with the commit requests we may have dropped
internalCluster().stopRandomNonMasterNode();
}
use of org.elasticsearch.test.transport.MockTransportService in project crate by crate.
the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.
@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
expectedException.expect(RepositoryException.class);
// add repo to cluster service so that it exists..
RepositoriesMetadata repos = new RepositoriesMetadata(Collections.singletonList(new RepositoryMetadata("repo1", "fs", Settings.EMPTY)));
ClusterState state = ClusterState.builder(new ClusterName("dummy")).metadata(Metadata.builder().putCustom(RepositoriesMetadata.TYPE, repos)).build();
ClusterServiceUtils.setState(clusterService, state);
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings());
TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
deleteRepoCalled.set(true);
listener.onResponse(mock(AcknowledgedResponse.class));
}
};
TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {
@Override
protected void doExecute(PutRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
listener.onFailure(new RepositoryException(request.name(), "failure"));
}
};
RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
try {
PutRepositoryRequest request = new PutRepositoryRequest("repo1");
request.type("fs");
repositoryService.execute(request).get(10, TimeUnit.SECONDS);
} catch (ExecutionException e) {
assertThat(deleteRepoCalled.get(), is(true));
throw e.getCause();
}
}
use of org.elasticsearch.test.transport.MockTransportService in project crate by crate.
the class TransportClusterStateActionDisruptionIT method runRepeatedlyWhileChangingMaster.
public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception {
internalCluster().startNodes(3);
assertBusy(() -> assertThat(client().admin().cluster().prepareState().clear().setMetadata(true).get().getState().getLastCommittedConfiguration().getNodeIds().stream().filter(n -> ClusterBootstrapService.isBootstrapPlaceholder(n) == false).collect(Collectors.toSet()), hasSize(3)));
final String masterName = internalCluster().getMasterName();
final AtomicBoolean shutdown = new AtomicBoolean();
final Thread assertingThread = new Thread(() -> {
while (shutdown.get() == false) {
runnable.run();
}
}, "asserting thread");
final Thread updatingThread = new Thread(() -> {
String value = "none";
while (shutdown.get() == false) {
value = "none".equals(value) ? "all" : "none";
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
assertAcked(client(nonMasterNode).admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), value)));
}
}, "updating thread");
final List<MockTransportService> mockTransportServices = StreamSupport.stream(internalCluster().getInstances(TransportService.class).spliterator(), false).map(ts -> (MockTransportService) ts).collect(Collectors.toList());
assertingThread.start();
updatingThread.start();
final MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterName);
for (MockTransportService mockTransportService : mockTransportServices) {
if (masterTransportService != mockTransportService) {
masterTransportService.addFailToSendNoConnectRule(mockTransportService);
mockTransportService.addFailToSendNoConnectRule(masterTransportService);
}
}
assertBusy(() -> {
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
assertThat(claimedMasterName, not(equalTo(masterName)));
});
shutdown.set(true);
assertingThread.join();
updatingThread.join();
internalCluster().close();
}
Aggregations