Search in sources :

Example 1 with MockNode

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")));
}
Also used : MockNode(org.opensearch.node.MockNode) Settings(org.opensearch.common.settings.Settings)

Example 2 with MockNode

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);
}
Also used : MockNode(org.opensearch.node.MockNode) UncheckedIOException(java.io.UncheckedIOException) LifecycleListener(org.opensearch.common.component.LifecycleListener) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) SecureSettings(org.opensearch.common.settings.SecureSettings) Plugin(org.opensearch.plugins.Plugin)

Example 3 with MockNode

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;
}
Also used : Path(java.nio.file.Path) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) MockNode(org.opensearch.node.MockNode) NodeValidationException(org.opensearch.node.NodeValidationException) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) TransportSettings(org.opensearch.transport.TransportSettings) MockScriptService(org.opensearch.script.MockScriptService) Plugin(org.opensearch.plugins.Plugin)

Example 4 with MockNode

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]+")));
    }
}
Also used : MockNode(org.opensearch.node.MockNode) Settings(org.opensearch.common.settings.Settings)

Example 5 with MockNode

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]+")));
    }
}
Also used : MockNode(org.opensearch.node.MockNode) Settings(org.opensearch.common.settings.Settings)

Aggregations

MockNode (org.opensearch.node.MockNode)6 Settings (org.opensearch.common.settings.Settings)5 Path (java.nio.file.Path)2 DiskThresholdSettings (org.opensearch.cluster.routing.allocation.DiskThresholdSettings)2 Node (org.opensearch.node.Node)2 Plugin (org.opensearch.plugins.Plugin)2 NodeRoles.dataNode (org.opensearch.test.NodeRoles.dataNode)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 LifecycleListener (org.opensearch.common.component.LifecycleListener)1 MockSecureSettings (org.opensearch.common.settings.MockSecureSettings)1 SecureSettings (org.opensearch.common.settings.SecureSettings)1 IndexSettings (org.opensearch.index.IndexSettings)1 NodeValidationException (org.opensearch.node.NodeValidationException)1 MockScriptService (org.opensearch.script.MockScriptService)1 InternalSettingsPlugin (org.opensearch.test.InternalSettingsPlugin)1 MockTransportService (org.opensearch.test.transport.MockTransportService)1 TransportService (org.opensearch.transport.TransportService)1