Search in sources :

Example 11 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class UnsafeBootstrapAndDetachCommandIT method test3MasterNodes2Failed.

@Test
@UseJdbc(0)
public void test3MasterNodes2Failed() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> masterNodes = new ArrayList<>();
    logger.info("--> start 1st master-eligible node");
    masterNodes.add(internalCluster().startMasterOnlyNode(Settings.builder().put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()));
    logger.info("--> start one data-only node");
    String dataNode = internalCluster().startDataOnlyNode(Settings.builder().put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build());
    logger.info("--> start 2nd and 3rd master-eligible nodes and bootstrap");
    // node ordinals 2 and 3
    masterNodes.addAll(internalCluster().startMasterOnlyNodes(2));
    logger.info("--> wait for all nodes to join the cluster");
    ensureStableCluster(4);
    logger.info("--> create index test");
    execute("create table doc.test (x int)");
    ensureGreen("test");
    Settings master1DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(0));
    Settings master2DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(1));
    Settings master3DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(2));
    Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);
    logger.info("--> stop 2nd and 3d master eligible node");
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(2)));
    logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    logger.info("--> try to unsafely bootstrap 1st master-eligible node, while node lock is held");
    Environment environmentMaster1 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master1DataPathSettings).build());
    expectThrows(() -> unsafeBootstrap(environmentMaster1), UnsafeBootstrapMasterCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
    logger.info("--> stop 1st master-eligible node and data-only node");
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
    internalCluster().stopRandomDataNode();
    logger.info("--> unsafely-bootstrap 1st master-eligible node");
    MockTerminal terminal = unsafeBootstrap(environmentMaster1);
    Metadata metadata = ElasticsearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, nodeEnvironment.nodeDataPaths()).loadBestOnDiskState().metadata;
    assertThat(terminal.getOutput(), containsString(String.format(Locale.ROOT, UnsafeBootstrapMasterCommand.CLUSTER_STATE_TERM_VERSION_MSG_FORMAT, metadata.coordinationMetadata().term(), metadata.version())));
    logger.info("--> start 1st master-eligible node");
    internalCluster().startMasterOnlyNode(master1DataPathSettings);
    logger.info("--> detach-cluster on data-only node");
    Environment environmentData = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).build());
    detachCluster(environmentData, false);
    logger.info("--> start data-only node");
    String dataNode2 = internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
    logger.info("--> ensure there is no NO_MASTER_BLOCK and unsafe-bootstrap is reflected in cluster state");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode2).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertFalse(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
        assertTrue(state.metadata().persistentSettings().getAsBoolean(UnsafeBootstrapMasterCommand.UNSAFE_BOOTSTRAP.getKey(), false));
    });
    logger.info("--> ensure index test is green");
    ensureGreen("test");
    logger.info("--> detach-cluster on 2nd and 3rd master-eligible nodes");
    Environment environmentMaster2 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master2DataPathSettings).build());
    detachCluster(environmentMaster2, false);
    Environment environmentMaster3 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master3DataPathSettings).build());
    detachCluster(environmentMaster3, false);
    logger.info("--> start 2nd and 3rd master-eligible nodes and ensure 4 nodes stable cluster");
    internalCluster().startMasterOnlyNode(master2DataPathSettings);
    internalCluster().startMasterOnlyNode(master3DataPathSettings);
    ensureStableCluster(4);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) Metadata(org.elasticsearch.cluster.metadata.Metadata) NodeMetadata(org.elasticsearch.env.NodeMetadata) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) TestEnvironment(org.elasticsearch.env.TestEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) MockTerminal(org.elasticsearch.cli.MockTerminal) Settings(org.elasticsearch.common.settings.Settings) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 12 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class CopyFromFailFastITest method test_copy_from_with_fail_fast_with_single_node.

@UseJdbc(0)
@Test
public void test_copy_from_with_fail_fast_with_single_node() throws Exception {
    internalCluster().startNode();
    internalCluster().ensureAtLeastNumDataNodes(1);
    // a single uri with 'shared = true' implies that one node will be involved at all times.
    Path tmpDir = newTempDir(LifecycleScope.TEST);
    Path target = Files.createDirectories(tmpDir.resolve("target"));
    tmpFileWithLines(Arrays.asList(("{\"a\":987654321},".repeat(10) + "{\"a\":\"fail here\"}," + "{\"a\":123456789},".repeat(10)).split(",")), "data1.json", target);
    execute("CREATE TABLE t (a int) CLUSTERED INTO 1 SHARDS");
    assertThrowsMatches(() -> execute(// fail_fast = true
    "COPY t FROM ? WITH (bulk_size = 1, fail_fast = true)", new Object[] { target.toUri() + "*" }), JobKilledException.class, "ERRORS: {failed to parse field");
}
Also used : Path(java.nio.file.Path) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 13 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class JobLogIntegrationTest method testJobLogWithEnabledAndDisabledStats.

@Test
// SET extra_float_digits = 3 gets added to the jobs_log
@UseJdbc(0)
public void testJobLogWithEnabledAndDisabledStats() throws Exception {
    String setStmt = "set global transient stats.jobs_log_size=1";
    execute(setStmt);
    // We record the statements in the log **after** we notify the result receivers (see {@link JobsLogsUpdateListener usage).
    // So it might happen that the "set global ..." statement execution is returned to this test but the recording
    // in the log is done AFTER the execution of the below "select name from sys.cluster" statement (because async
    // programming is evil like that). And then this test will fail and people will spend days and days to figure
    // out what's going on.
    // So let's just wait for the "set global ... " statement to be recorded here and then move on with our test.
    assertBusy(() -> {
        boolean setStmtFound = false;
        for (JobsLogService jobsLogService : internalCluster().getDataNodeInstances(JobsLogService.class)) {
            // each node must have received the new jobs_log_size setting change instruction
            assertThat(jobsLogService.jobsLogSize(), is(1));
            JobsLogs jobsLogs = jobsLogService.get();
            Iterator<JobContextLog> iterator = jobsLogs.jobsLog().iterator();
            if (iterator.hasNext()) {
                if (iterator.next().statement().equalsIgnoreCase(setStmt)) {
                    setStmtFound = true;
                }
            }
        }
        // at least one node must have the set statement logged
        assertThat(setStmtFound, is(true));
    });
    // only the latest queries are found in the log.
    for (SQLOperations sqlOperations : internalCluster().getDataNodeInstances(SQLOperations.class)) {
        Session session = sqlOperations.newSystemSession();
        execute("select name from sys.cluster", null, session);
    }
    assertJobLogOnNodesHaveOnlyStatement("select name from sys.cluster");
    for (SQLOperations sqlOperations : internalCluster().getDataNodeInstances(SQLOperations.class)) {
        Session session = sqlOperations.newSystemSession();
        execute("select id from sys.cluster", null, session);
    }
    assertJobLogOnNodesHaveOnlyStatement("select id from sys.cluster");
    execute("set global transient stats.enabled = false");
    for (JobsLogService jobsLogService : internalCluster().getDataNodeInstances(JobsLogService.class)) {
        assertBusy(() -> assertThat(jobsLogService.isEnabled(), is(false)));
    }
    execute("select * from sys.jobs_log");
    assertThat(response.rowCount(), is(0L));
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) SQLOperations(io.crate.action.sql.SQLOperations) JobsLogService(io.crate.execution.engine.collect.stats.JobsLogService) Session(io.crate.action.sql.Session) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 14 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class NodeStatsTest method testThreadPools.

@SuppressWarnings("ConstantConditions")
@Test
// because of json some values are transfered as integer instead of long
@UseJdbc(0)
public void testThreadPools() throws Exception {
    SQLResponse response = execute("select thread_pools from sys.nodes limit 1");
    List threadPools = (List) response.rows()[0][0];
    assertThat(threadPools.size(), greaterThanOrEqualTo(1));
    Map<String, Object> threadPool = null;
    for (Object t : threadPools) {
        Map<String, Object> map = (Map<String, Object>) t;
        if (map.get("name").equals("generic")) {
            threadPool = map;
            break;
        }
    }
    assertThat(threadPool.get("name"), is("generic"));
    assertThat((Integer) threadPool.get("active"), greaterThanOrEqualTo(0));
    assertThat((Long) threadPool.get("rejected"), greaterThanOrEqualTo(0L));
    assertThat((Integer) threadPool.get("largest"), greaterThanOrEqualTo(0));
    assertThat((Long) threadPool.get("completed"), greaterThanOrEqualTo(0L));
    assertThat((Integer) threadPool.get("threads"), greaterThanOrEqualTo(0));
    assertThat((Integer) threadPool.get("queue"), greaterThanOrEqualTo(0));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Aggregations

UseJdbc (io.crate.testing.UseJdbc)14 Test (org.junit.Test)14 SQLResponse (io.crate.testing.SQLResponse)8 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 List (java.util.List)3 ArrayList (java.util.ArrayList)2 SQLOperations (io.crate.action.sql.SQLOperations)1 Session (io.crate.action.sql.Session)1 JobsLogService (io.crate.execution.engine.collect.stats.JobsLogService)1 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)1 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)1 UseRandomizedSchema (io.crate.testing.UseRandomizedSchema)1 Path (java.nio.file.Path)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Properties (java.util.Properties)1 MockTerminal (org.elasticsearch.cli.MockTerminal)1 ClusterState (org.elasticsearch.cluster.ClusterState)1