Search in sources :

Example 6 with ClientCache

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

the class CacheEntryListenersTest method testListenersUnsupportedParameters.

/**
 */
@Test
@SuppressWarnings({ "ThrowableNotThrown", "deprecation" })
public void testListenersUnsupportedParameters() throws Exception {
    try (IgniteClient client = startClient(0, 1, 2)) {
        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testUnsupportedParams");
        // Check null listener factory.
        CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg1 = new MutableCacheEntryListenerConfiguration<>(null, null, true, false);
        assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg1), NullPointerException.class);
        // Check synchronous flag.
        CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg2 = new MutableCacheEntryListenerConfiguration<>(JCacheEntryListener::new, null, true, true);
        assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg2), IllegalArgumentException.class);
        // Check local flag.
        ContinuousQueryListener<Integer, Integer> cqLsnr = new ContinuousQueryListener<>();
        ContinuousQuery<Integer, Integer> qry1 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setLocal(true);
        assertThrowsWithCause(() -> cache.query(qry1), IllegalArgumentException.class);
        // Check null listener.
        ContinuousQuery<Integer, Integer> qry2 = new ContinuousQuery<>();
        assertThrowsWithCause(() -> cache.query(qry2), NullPointerException.class);
        // Check auto unsubscribe flag.
        ContinuousQuery<Integer, Integer> qry3 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setAutoUnsubscribe(false);
        assertThrowsWithCause(() -> cache.query(qry3), IllegalArgumentException.class);
        // Check continuous query as initial query.
        ContinuousQuery<Integer, Integer> qry4 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setInitialQuery(new ContinuousQuery<>());
        assertThrowsWithCause(() -> cache.query(qry4), IllegalArgumentException.class);
        // Check filter factory and filter defined at the same time.
        CacheEntryEventSerializableFilter<Integer, Integer> rmtFilter = r -> true;
        ContinuousQuery<Integer, Integer> qry5 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setRemoteFilter(rmtFilter);
        qry5.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFilter));
        assertThrowsWithCause(() -> cache.query(qry5), IllegalArgumentException.class);
    }
}
Also used : IntStream(java.util.stream.IntStream) ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) Person(org.apache.ignite.client.Person) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) CacheEntryExpiredListener(javax.cache.event.CacheEntryExpiredListener) ClientCache(org.apache.ignite.client.ClientCache) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) CacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClient(org.apache.ignite.client.IgniteClient) Map(java.util.Map) Cache(javax.cache.Cache) CacheEntryCreatedListener(javax.cache.event.CacheEntryCreatedListener) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) Duration(javax.cache.expiry.Duration) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) F(org.apache.ignite.internal.util.typedef.F) EventType(javax.cache.event.EventType) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) EnumMap(java.util.EnumMap) FactoryBuilder(javax.cache.configuration.FactoryBuilder) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) UUID(java.util.UUID) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) T2(org.apache.ignite.internal.util.typedef.T2) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheEntryRemovedListener(javax.cache.event.CacheEntryRemovedListener) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 7 with ClientCache

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

the class TestClusterClientConnection method testClientConnectsToCluster.

/**
 */
@Test
public void testClientConnectsToCluster() throws Exception {
    mockServerResponse();
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(), false);
    IgniteEx crd = startGrid(cfg);
    String crdAddr = crd.localNode().addresses().iterator().next();
    mockServerResponse(crdAddr);
    ClientConfiguration ccfg = new ClientConfiguration();
    ccfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(prepareConfiguration()));
    IgniteClient client = Ignition.startClient(ccfg);
    ClientCache cache = client.createCache("cache");
    cache.put(1, 2);
    assertEquals(2, cache.get(1));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) ClientCache(org.apache.ignite.client.ClientCache) ThinClientKubernetesAddressFinder(org.apache.ignite.client.ThinClientKubernetesAddressFinder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientCache (org.apache.ignite.client.ClientCache)7 IgniteClient (org.apache.ignite.client.IgniteClient)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)6 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)5 Cache (javax.cache.Cache)5 CacheEntryEvent (javax.cache.event.CacheEntryEvent)5 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)5 Duration (javax.cache.expiry.Duration)5 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)5 ScanQuery (org.apache.ignite.cache.query.ScanQuery)5 Person (org.apache.ignite.client.Person)5 ClientConnectorConfiguration (org.apache.ignite.configuration.ClientConnectorConfiguration)5 F (org.apache.ignite.internal.util.typedef.F)5 EnumMap (java.util.EnumMap)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 UUID (java.util.UUID)4