use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.
the class AzureRepositoryF method main.
public static void main(String[] args) throws Throwable {
Settings.Builder settings = Settings.builder();
settings.put("http.cors.enabled", "true");
settings.put("http.cors.allow-origin", "*");
settings.put("cluster.name", AzureRepositoryF.class.getSimpleName());
// Example for azure repo settings
// settings.put("cloud.azure.storage.my_account1.account", "account_name");
// settings.put("cloud.azure.storage.my_account1.key", "account_key");
// settings.put("cloud.azure.storage.my_account1.default", true);
// settings.put("cloud.azure.storage.my_account2.account", "account_name");
// settings.put("cloud.azure.storage.my_account2.key", "account_key_secondary");
final CountDownLatch latch = new CountDownLatch(1);
final Node node = new MockNode(settings.build(), Collections.singletonList(AzureRepositoryPlugin.class));
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
IOUtils.close(node);
} catch (IOException e) {
throw new ElasticsearchException(e);
} finally {
latch.countDown();
}
}
});
node.start();
latch.await();
}
use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.
the class InternalTestCluster method buildNode.
/**
* builds a new node
*
* @param nodeId the node internal id (see {@link NodeAndClient#nodeAndClientId()}
* @param seed the node's random seed
* @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 defaultMinMasterNodes min_master_nodes value to use if min_master_nodes is auto managed
*/
private NodeAndClient buildNode(int nodeId, long seed, Settings settings, boolean reuseExisting, int defaultMinMasterNodes) {
assert Thread.holdsLock(this);
ensureOpen();
settings = getSettings(nodeId, seed, settings);
Collection<Class<? extends Plugin>> plugins = getPlugins();
String name = buildNodeName(nodeId, settings);
if (reuseExisting && nodes.containsKey(name)) {
return nodes.get(name);
} else {
assert reuseExisting == true || nodes.containsKey(name) == false : "node name [" + name + "] already exists but not allowed to use it";
}
Settings.Builder finalSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), // allow overriding path.home
baseDir).put(settings).put("node.name", name).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), seed);
if (autoManageMinMasterNodes) {
assert finalSettings.get(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()) == null : "min master nodes may not be set when auto managed";
finalSettings.put(ZenDiscovery.MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING.getKey(), "5s").put(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), defaultMinMasterNodes);
} else if (finalSettings.get(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()) == null) {
throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
}
MockNode node = new MockNode(finalSettings.build(), plugins);
return new NodeAndClient(name, node, nodeId);
}
use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.
the class ESSingleNodeTestCase method newNode.
private Node newNode() {
final Path tempDir = createTempDir();
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.name", "node_s_0").put("script.inline", "true").put("script.stored", "true").put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 1000).put(EsExecutors.PROCESSORS_SETTING.getKey(), // limit the number of threads created
1).put(NetworkModule.HTTP_ENABLED.getKey(), false).put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(Node.NODE_DATA_SETTING.getKey(), true).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).put(// allow test cases to provide their own settings or override these
nodeSettings()).build();
Collection<Class<? extends Plugin>> plugins = getPlugins();
if (plugins.contains(MockTcpTransportPlugin.class) == false) {
plugins = new ArrayList<>(plugins);
plugins.add(MockTcpTransportPlugin.class);
}
if (plugins.contains(TestZenDiscovery.TestPlugin.class) == false) {
plugins = new ArrayList<>(plugins);
plugins.add(TestZenDiscovery.TestPlugin.class);
}
Node build = new MockNode(settings, plugins);
try {
build.start();
} catch (NodeValidationException e) {
throw new RuntimeException(e);
}
return build;
}
use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.
the class TribeUnitTests method createTribes.
@BeforeClass
public static void createTribes() throws NodeValidationException {
Settings baseSettings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2).build();
final List<Class<? extends Plugin>> mockPlugins = Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class);
tribe1 = new MockNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe1").put("node.name", "tribe1_node").put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).build(), mockPlugins).start();
tribe2 = new MockNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe2").put("node.name", "tribe2_node").put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).build(), mockPlugins).start();
}
use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.
the class TransportClientIT method testNodeVersionIsUpdated.
public void testNodeVersionIsUpdated() throws IOException, NodeValidationException {
TransportClient client = (TransportClient) internalCluster().client();
try (Node node = new MockNode(Settings.builder().put(internalCluster().getDefaultSettings()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put("node.name", "testNodeVersionIsUpdated").put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(NetworkModule.HTTP_ENABLED.getKey(), false).put(Node.NODE_DATA_SETTING.getKey(), false).put("cluster.name", "foobar").build(), Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class)).start()) {
TransportAddress transportAddress = node.injector().getInstance(TransportService.class).boundAddress().publishAddress();
client.addTransportAddress(transportAddress);
// since we force transport clients there has to be one node started that we connect to.
assertThat(client.connectedNodes().size(), greaterThanOrEqualTo(1));
// connected nodes have updated version
for (DiscoveryNode discoveryNode : client.connectedNodes()) {
assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT));
}
for (DiscoveryNode discoveryNode : client.listedNodes()) {
assertThat(discoveryNode.getId(), startsWith("#transport#-"));
assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
}
assertThat(client.filteredNodes().size(), equalTo(1));
for (DiscoveryNode discoveryNode : client.filteredNodes()) {
assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
}
}
}
Aggregations