Search in sources :

Example 86 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ComputeTaskTest method testExecuteTaskAsync2WithExceptionInTask.

/**
 * Tests asynchronous task execution with an exception.
 */
@Test
public void testExecuteTaskAsync2WithExceptionInTask() throws Exception {
    try (IgniteClient client = startClient(0)) {
        IgniteClientFuture<Object> fut = client.compute().executeAsync2(TestExceptionalTask.class.getName(), null);
        String errMessage = fut.handle((f, t) -> t.getMessage()).toCompletableFuture().get(2, TimeUnit.SECONDS);
        assertTrue(errMessage.contains("cause=Foo"));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 87 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class CacheEntryListenersTest method testListenersClose.

/**
 */
@Test
public void testListenersClose() throws Exception {
    try (IgniteClient client = startClient(0, 1, 2)) {
        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testListenersClose");
        ContinuousQueryListener<Integer, Integer> lsnr1 = new ContinuousQueryListener<>();
        QueryCursor<?> qry = cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr1));
        JCacheEntryListener<Integer, Integer> lsnr2 = new JCacheEntryListener<>();
        CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(() -> lsnr2, null, true, false);
        cache.registerCacheEntryListener(lsnrCfg);
        cache.put(0, 0);
        lsnr1.assertNextCacheEvent(EventType.CREATED, 0, 0);
        lsnr2.assertNextCacheEvent(EventType.CREATED, 0, 0);
        qry.close();
        cache.deregisterCacheEntryListener(lsnrCfg);
        for (int i = 0; i < 100; i++) cache.put(i, i);
        assertTrue(lsnr1.isQueueEmpty());
        assertTrue(lsnr2.isQueueEmpty());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) Test(org.junit.Test)

Example 88 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class CacheEntryListenersTest method testContinuousQueriesWithTimeInterval.

/**
 * Test continuous queries with time interval parameter.
 */
@Test
public void testContinuousQueriesWithTimeInterval() throws Exception {
    try (IgniteClient client = startClient(1, 2)) {
        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithTimeInterval");
        IgniteCache<Integer, Integer> nodeCache = grid(0).getOrCreateCache(cache.getName());
        ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
        ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr).setPageSize(10).setTimeInterval(TIMEOUT);
        long ts1 = U.currentTimeMillis();
        cache.query(qry);
        // Put data to the remote node.
        int key = primaryKey(nodeCache);
        cache.put(key, key);
        assertNotNull(lsnr.poll(TIMEOUT * 2));
        assertTrue(lsnr.isQueueEmpty());
        long ts2 = U.currentTimeMillis();
        // Ensure that item was received after timeout.
        assertTrue("ts2 - ts1 = " + (ts2 - ts1), ts2 - ts1 >= TIMEOUT);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 89 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class CacheEntryListenersTest method testContinuousQueriesWithInitialQuery.

/**
 * Test continuous queries with initial query.
 */
@Test
public void testContinuousQueriesWithInitialQuery() throws Exception {
    try (IgniteClient client = startClient(0, 1, 2)) {
        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithInitQ");
        for (int i = 0; i < 100; i++) cache.put(i, i);
        ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
        QueryCursor<Cache.Entry<Integer, Integer>> cur = cache.query(new ContinuousQuery<Integer, Integer>().setInitialQuery(new ScanQuery<>()).setLocalListener(lsnr));
        assertTrue(lsnr.isQueueEmpty());
        assertEquals(100, cur.getAll().size());
        cache.put(100, 100);
        lsnr.assertNextCacheEvent(EventType.CREATED, 100, 100);
        cache.put(100, 101);
        lsnr.assertNextCacheEvent(EventType.UPDATED, 100, 101);
        cache.remove(100);
        lsnr.assertNextCacheEvent(EventType.REMOVED, 100);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 90 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class CacheEntryListenersTest method testContinuousQueriesWithPageSize.

/**
 * Test continuous queries with page size parameter.
 */
@Test
public void testContinuousQueriesWithPageSize() throws Exception {
    try (IgniteClient client = startClient(1, 2)) {
        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithPageSize");
        IgniteCache<Integer, Integer> nodeCache = grid(0).getOrCreateCache(cache.getName());
        ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
        ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr).setPageSize(10);
        cache.query(qry);
        // Each node has its own buffer, put data to the exactly one remote node.
        primaryKeys(nodeCache, 15).forEach(key -> cache.put(key, key));
        // Check that only first page is received.
        aggregateListenerEvents(lsnr, 10);
        assertTrue(lsnr.isQueueEmpty());
        primaryKeys(nodeCache, 6).forEach(key -> cache.put(key, key));
        // Check that only second page is received.
        aggregateListenerEvents(lsnr, 10);
        assertTrue(lsnr.isQueueEmpty());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9