Search in sources :

Example 1 with DataStreamerRequest

use of org.apache.ignite.internal.processors.datastreamer.DataStreamerRequest in project ignite by apache.

the class KillQueryTest method testBulkLoadCancellationUnsupported.

/**
 * Tries to cancel COPY FROM command, then checks such cancellation is unsupported.
 *
 * 1) Run COPY query, got it suspended in the middle.
 * 2) Try to cancel it, get expected exception.
 * 3) Wake up the COPY.
 * 4) Check COPY is done.
 */
@Test
public void testBulkLoadCancellationUnsupported() throws Exception {
    String path = Objects.requireNonNull(resolveIgnitePath("/modules/clients/src/test/resources/bulkload1.csv")).getAbsolutePath();
    String createTab = "CREATE TABLE " + currentTestTableName() + "(id integer primary key, age integer, firstName varchar, lastname varchar)";
    String copy = "COPY FROM '" + path + "'" + " INTO " + currentTestTableName() + " (id, age, firstName, lastName)" + " format csv charset 'ascii'";
    // It's importaint to COPY from the client node: in this case datastreamer doesn't perform local updates so
    // it sends communication messages which we can hold.
    IgniteEx clientNode = grid(NODES_COUNT - 1);
    try (Connection clConn = GridTestUtils.connect(clientNode, null);
        final Statement client = clConn.createStatement()) {
        client.execute(createTab);
        // Suspend further copy query by holding data streamer messages.
        clientBlocker.blockMessages((dstNode, msg) -> msg instanceof DataStreamerRequest);
        IgniteInternalFuture<Boolean> copyIsDone = GridTestUtils.runAsync(() -> client.execute(copy));
        // Wait at least one streamer message, that means copy started.
        clientBlocker.waitForBlocked(1, TIMEOUT);
        // Query can be found only on the connected node.
        String globQryId = findOneRunningQuery(copy, clientNode);
        GridTestUtils.assertThrowsAnyCause(log, () -> igniteForKillRequest.cache(DEFAULT_CACHE_NAME).query(createKillQuery(globQryId, asyncCancel)), CacheException.class, "Query doesn't support cancellation");
        // Releases copy.
        clientBlocker.stopBlock(true);
        copyIsDone.get(TIMEOUT);
        int tabSize = clientNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("SELECT * FROM " + currentTestTableName() + " ").setSchema("PUBLIC")).getAll().size();
        assertEquals("COPY command inserted incorrect number of rows.", 1, tabSize);
    }
}
Also used : Statement(java.sql.Statement) IgniteEx(org.apache.ignite.internal.IgniteEx) Connection(java.sql.Connection) DataStreamerRequest(org.apache.ignite.internal.processors.datastreamer.DataStreamerRequest) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 DataStreamerRequest (org.apache.ignite.internal.processors.datastreamer.DataStreamerRequest)1 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1