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);
}
}
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));
}
Aggregations