use of org.opensearch.node.MockNode in project OpenSearch by opensearch-project.
the class IndexStorePluginTests method testIndexStoreFactoryConflictsWithBuiltInIndexStoreType.
public void testIndexStoreFactoryConflictsWithBuiltInIndexStoreType() {
final Settings settings = Settings.builder().put("path.home", createTempDir()).build();
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new MockNode(settings, Collections.singletonList(ConflictingStorePlugin.class)));
assertThat(e, hasToString(containsString("registered index store type [" + ConflictingStorePlugin.TYPE + "] conflicts with a built-in type")));
}
use of org.opensearch.node.MockNode in project OpenSearch by opensearch-project.
the class InternalTestCluster method buildNode.
/**
* builds a new node
*
* @param nodeId node ordinal
* @param settings the settings to use
* @param reuseExisting if a node with the same name is already part of {@link #nodes}, no new node will be built and
* the method will return the existing one
* @param onTransportServiceStarted callback to run when transport service is started
*/
private synchronized NodeAndClient buildNode(int nodeId, Settings settings, boolean reuseExisting, Runnable onTransportServiceStarted) {
assert Thread.holdsLock(this);
ensureOpen();
Collection<Class<? extends Plugin>> plugins = getPlugins();
String name = settings.get("node.name");
final NodeAndClient nodeAndClient = nodes.get(name);
if (reuseExisting && nodeAndClient != null) {
// reusing an existing node implies its transport service already started
onTransportServiceStarted.run();
return nodeAndClient;
}
assert reuseExisting || nodeAndClient == null : "node name [" + name + "] already exists but not allowed to use it";
SecureSettings secureSettings = Settings.builder().put(settings).getSecureSettings();
if (secureSettings instanceof MockSecureSettings) {
// we clone this here since in the case of a node restart we might need it again
secureSettings = ((MockSecureSettings) secureSettings).clone();
}
MockNode node = new MockNode(settings, plugins, nodeConfigurationSource.nodeConfigPath(nodeId), forbidPrivateIndexSettings);
node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {
@Override
public void afterStart() {
onTransportServiceStarted.run();
}
});
try {
IOUtils.close(secureSettings);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new NodeAndClient(name, node, settings, nodeId);
}
use of org.opensearch.node.MockNode in project OpenSearch by opensearch-project.
the class OpenSearchSingleNodeTestCase method newNode.
private Node newNode() {
final Path tempDir = createTempDir();
final String nodeName = nodeSettings().get(Node.NODE_NAME_SETTING.getKey(), "node_s_0");
Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), InternalTestCluster.clusterName("single-node-cluster", random().nextLong())).put(Environment.PATH_HOME_SETTING.getKey(), tempDir).put(Environment.PATH_REPO_SETTING.getKey(), tempDir.resolve("repo")).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), createTempDir().getParent()).put(Node.NODE_NAME_SETTING.getKey(), nodeName).put(OpenSearchExecutors.NODE_PROCESSORS_SETTING.getKey(), // limit the number of threads created
1).put("transport.type", getTestTransportType()).put(TransportSettings.PORT.getKey(), getPortRange()).put(dataNode()).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "1b").put(HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.getKey(), false).putList(// empty list disables a port scan for other nodes
DISCOVERY_SEED_HOSTS_SETTING.getKey()).putList(INITIAL_MASTER_NODES_SETTING.getKey(), nodeName).put(// allow test cases to provide their own settings or override these
nodeSettings()).build();
Collection<Class<? extends Plugin>> plugins = getPlugins();
if (plugins.contains(getTestTransportPlugin()) == false) {
plugins = new ArrayList<>(plugins);
plugins.add(getTestTransportPlugin());
}
if (addMockHttpTransport()) {
plugins.add(MockHttpTransport.TestPlugin.class);
}
plugins.add(MockScriptService.TestPlugin.class);
Node node = new MockNode(settings, plugins, forbidPrivateIndexSettings());
try {
node.start();
} catch (NodeValidationException e) {
throw new RuntimeException(e);
}
return node;
}
use of org.opensearch.node.MockNode in project OpenSearch by opensearch-project.
the class IndexStorePluginTests method testDuplicateIndexStoreFactories.
public void testDuplicateIndexStoreFactories() {
final Settings settings = Settings.builder().put("path.home", createTempDir()).build();
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new MockNode(settings, Arrays.asList(BarStorePlugin.class, FooStorePlugin.class)));
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
assertThat(e, hasToString(matches("java.lang.IllegalStateException: Duplicate key store \\(attempted merging values " + "org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+ " + "and org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+\\)")));
} else {
assertThat(e, hasToString(matches("java.lang.IllegalStateException: Duplicate key org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+")));
}
}
use of org.opensearch.node.MockNode in project OpenSearch by opensearch-project.
the class IndexStorePluginTests method testDuplicateIndexStoreRecoveryStateFactories.
public void testDuplicateIndexStoreRecoveryStateFactories() {
final Settings settings = Settings.builder().put("path.home", createTempDir()).build();
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new MockNode(settings, Arrays.asList(FooCustomRecoveryStore.class, BarCustomRecoveryStore.class)));
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
assertThat(e.getMessage(), containsString("Duplicate key recovery-type"));
} else {
assertThat(e, hasToString(matches("java.lang.IllegalStateException: Duplicate key " + "org.opensearch.plugins.IndexStorePluginTests\\$RecoveryFactory@[\\w\\d]+")));
}
}
Aggregations