use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.
the class SingleNodeDiscoveryIT method testCannotJoinNodeWithSingleNodeDiscovery.
public void testCannotJoinNodeWithSingleNodeDiscovery() throws Exception {
Logger clusterLogger = LogManager.getLogger(JoinHelper.class);
try (MockLogAppender mockAppender = MockLogAppender.createForLoggers(clusterLogger)) {
mockAppender.addExpectation(new MockLogAppender.SeenEventExpectation("test", JoinHelper.class.getCanonicalName(), Level.INFO, "failed to join") {
@Override
public boolean innerMatch(final LogEvent event) {
return event.getThrown() != null && event.getThrown().getClass() == RemoteTransportException.class && event.getThrown().getCause() != null && event.getThrown().getCause().getClass() == IllegalStateException.class && event.getThrown().getCause().getMessage().contains("cannot join node with [discovery.type] set to [single-node]");
}
});
final TransportService service = internalCluster().getInstance(TransportService.class);
final int port = service.boundAddress().publishAddress().getPort();
final NodeConfigurationSource configurationSource = new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put("discovery.type", "zen").put("transport.type", getTestTransportType()).put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").put("transport.port", port + "-" + (port + 5 - 1)).build();
}
@Override
public Path nodeConfigPath(int nodeOrdinal) {
return null;
}
};
try (InternalTestCluster other = new InternalTestCluster(randomLong(), createTempDir(), false, false, 1, 1, internalCluster().getClusterName(), configurationSource, 0, "other", Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class), Function.identity())) {
other.beforeTest(random());
final ClusterState first = internalCluster().getInstance(ClusterService.class).state();
assertThat(first.nodes().getSize(), equalTo(1));
assertBusy(() -> mockAppender.assertAllExpectationsMatched());
}
}
}
use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.
the class ClusterInfoServiceIT method testClusterInfoServiceCollectsInformation.
public void testClusterInfoServiceCollectsInformation() {
internalCluster().startNodes(2);
final String indexName = randomBoolean() ? randomAlphaOfLength(5).toLowerCase(Locale.ROOT) : TEST_SYSTEM_INDEX_NAME;
assertAcked(prepareCreate(indexName).setSettings(Settings.builder().put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), 0).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE).put(IndexMetadata.SETTING_INDEX_HIDDEN, randomBoolean()).build()));
if (randomBoolean()) {
assertAcked(client().admin().indices().prepareClose(indexName));
}
ensureGreen(indexName);
InternalTestCluster internalTestCluster = internalCluster();
// Get the cluster info service on the master node
final InternalClusterInfoService infoService = (InternalClusterInfoService) internalTestCluster.getInstance(ClusterInfoService.class, internalTestCluster.getMasterName());
infoService.setUpdateFrequency(TimeValue.timeValueMillis(200));
ClusterInfo info = infoService.refresh();
assertNotNull("info should not be null", info);
ImmutableOpenMap<String, DiskUsage> leastUsages = info.getNodeLeastAvailableDiskUsages();
ImmutableOpenMap<String, DiskUsage> mostUsages = info.getNodeMostAvailableDiskUsages();
ImmutableOpenMap<String, Long> shardSizes = info.shardSizes;
assertNotNull(leastUsages);
assertNotNull(shardSizes);
assertThat("some usages are populated", leastUsages.values().size(), Matchers.equalTo(2));
assertThat("some shard sizes are populated", shardSizes.values().size(), greaterThan(0));
for (ObjectCursor<DiskUsage> usage : leastUsages.values()) {
logger.info("--> usage: {}", usage.value);
assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L));
}
for (ObjectCursor<DiskUsage> usage : mostUsages.values()) {
logger.info("--> usage: {}", usage.value);
assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L));
}
for (ObjectCursor<Long> size : shardSizes.values()) {
logger.info("--> shard size: {}", size.value);
assertThat("shard size is greater than 0", size.value, greaterThanOrEqualTo(0L));
}
ClusterService clusterService = internalTestCluster.getInstance(ClusterService.class, internalTestCluster.getMasterName());
ClusterState state = clusterService.state();
for (ShardRouting shard : state.routingTable().allShards()) {
String dataPath = info.getDataPath(shard);
assertNotNull(dataPath);
String nodeId = shard.currentNodeId();
DiscoveryNode discoveryNode = state.getNodes().get(nodeId);
IndicesService indicesService = internalTestCluster.getInstance(IndicesService.class, discoveryNode.getName());
IndexService indexService = indicesService.indexService(shard.index());
IndexShard indexShard = indexService.getShardOrNull(shard.id());
assertEquals(indexShard.shardPath().getRootDataPath().toString(), dataPath);
assertTrue(info.getReservedSpace(nodeId, dataPath).containsShardId(shard.shardId()));
}
}
use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.
the class RepositoriesServiceIT method testUpdateRepository.
public void testUpdateRepository() {
final InternalTestCluster cluster = internalCluster();
final String repositoryName = "test-repo";
final Client client = client();
final RepositoriesService repositoriesService = cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next();
final Settings.Builder repoSettings = Settings.builder().put("location", randomRepoPath());
assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(FsRepository.TYPE).setSettings(repoSettings).get());
final GetRepositoriesResponse originalGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
assertThat(originalGetRepositoriesResponse.repositories(), hasSize(1));
RepositoryMetadata originalRepositoryMetadata = originalGetRepositoriesResponse.repositories().get(0);
assertThat(originalRepositoryMetadata.type(), equalTo(FsRepository.TYPE));
final Repository originalRepository = repositoriesService.repository(repositoryName);
assertThat(originalRepository, instanceOf(FsRepository.class));
final boolean updated = randomBoolean();
final String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE;
assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(updatedRepositoryType).setSettings(repoSettings).get());
final GetRepositoriesResponse updatedGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
assertThat(updatedGetRepositoriesResponse.repositories(), hasSize(1));
final RepositoryMetadata updatedRepositoryMetadata = updatedGetRepositoriesResponse.repositories().get(0);
assertThat(updatedRepositoryMetadata.type(), equalTo(updatedRepositoryType));
final Repository updatedRepository = repositoriesService.repository(repositoryName);
assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository));
}
use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.
the class MultiClusterRepoAccessIT method startSecondCluster.
@Before
public void startSecondCluster() throws IOException, InterruptedException {
repoPath = randomRepoPath();
secondCluster = new InternalTestCluster(randomLong(), createTempDir(), true, true, 0, 0, "second_cluster", new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(MultiClusterRepoAccessIT.this.nodeSettings(nodeOrdinal)).put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).put(Environment.PATH_REPO_SETTING.getKey(), repoPath).build();
}
@Override
public Path nodeConfigPath(int nodeOrdinal) {
return null;
}
}, 0, "leader", Arrays.asList(OpenSearchIntegTestCase.TestSeedPlugin.class, MockHttpTransport.TestPlugin.class, MockTransportService.TestPlugin.class, MockNioTransportPlugin.class, InternalSettingsPlugin.class, MockRepository.Plugin.class), Function.identity());
secondCluster.beforeTest(random());
}
use of org.opensearch.test.InternalTestCluster in project OpenSearch by opensearch-project.
the class InternalTestClusterTests method testTwoNodeCluster.
public void testTwoNodeCluster() throws Exception {
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file").putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()).build();
}
@Override
public Path nodeConfigPath(int nodeOrdinal) {
return null;
}
};
String nodePrefix = "test";
Path baseDir = createTempDir();
List<Class<? extends Plugin>> plugins = new ArrayList<>(mockPlugins());
plugins.add(NodeAttrCheckPlugin.class);
InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, false, true, 2, 2, "test", nodeConfigurationSource, 0, nodePrefix, plugins, Function.identity());
try {
cluster.beforeTest(random());
switch(randomInt(2)) {
case 0:
cluster.stopRandomDataNode();
cluster.startNode();
break;
case 1:
cluster.rollingRestart(InternalTestCluster.EMPTY_CALLBACK);
break;
case 2:
cluster.fullRestart();
break;
}
} finally {
cluster.close();
}
}
Aggregations