use of org.apache.ignite.client.ClientCache in project ignite by apache.
the class JavaThinClient method transactionConfiguration.
@Test
void transactionConfiguration() {
// tag::transaction-config[]
ClientConfiguration cfg = new ClientConfiguration();
cfg.setAddresses("localhost:10800");
cfg.setTransactionConfiguration(new ClientTransactionConfiguration().setDefaultTxTimeout(10000).setDefaultTxConcurrency(TransactionConcurrency.OPTIMISTIC).setDefaultTxIsolation(TransactionIsolation.REPEATABLE_READ));
IgniteClient client = Ignition.startClient(cfg);
// end::transaction-config[]
ClientCache cache = client.createCache(new ClientCacheConfiguration().setName("test").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
// tag::tx-custom-properties[]
ClientTransactions tx = client.transactions();
try (ClientTransaction t = tx.txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
cache.put(1, "new value");
t.commit();
}
// end::tx-custom-properties[]
}
use of org.apache.ignite.client.ClientCache in project ignite by apache.
the class CacheEntryListenersTest method testListenersWithRemoteFilter.
/**
* Test continuous queries and JCache entry listeners with remote filters.
*/
@Test
@SuppressWarnings("deprecation")
public void testListenersWithRemoteFilter() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testListenersWithRmtFilter");
CacheEntryEventSerializableFilter<Integer, Integer> rmtFilter = evt -> (evt.getKey() & 1) == 0;
ContinuousQueryListener<Integer, Integer> lsnr1 = new ContinuousQueryListener<>();
ContinuousQueryListener<Integer, Integer> lsnr2 = new ContinuousQueryListener<>();
cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr1).setRemoteFilterFactory(() -> rmtFilter));
cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr2).setRemoteFilter(rmtFilter));
JCacheEntryListener<Integer, Integer> lsnr3 = new JCacheEntryListener<>();
cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr3, () -> rmtFilter, true, false));
for (int i = 0; i < 10; i++) cache.put(i, i);
Map<EventType, Map<Integer, Integer>> expRes = F.asMap(EventType.CREATED, IntStream.range(0, 5).boxed().collect(Collectors.toMap(i -> i * 2, i -> i * 2)));
assertEquals(expRes, aggregateListenerEvents(lsnr1, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr2, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr3, 5));
for (int i = 0; i < 10; i++) cache.put(i, -i);
expRes = F.asMap(EventType.UPDATED, IntStream.range(0, 5).boxed().collect(Collectors.toMap(i -> i * 2, i -> -i * 2)));
assertEquals(expRes, aggregateListenerEvents(lsnr1, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr2, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr3, 5));
for (int i = 0; i < 10; i++) cache.remove(i);
expRes = F.asMap(EventType.REMOVED, IntStream.range(0, 5).boxed().collect(Collectors.toMap(i -> i * 2, i -> -i * 2)));
assertEquals(expRes, aggregateListenerEvents(lsnr1, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr2, 5));
assertEquals(expRes, aggregateListenerEvents(lsnr3, 5));
assertTrue(lsnr1.isQueueEmpty());
assertTrue(lsnr2.isQueueEmpty());
assertTrue(lsnr3.isQueueEmpty());
}
}
use of org.apache.ignite.client.ClientCache in project ignite by apache.
the class JavaThinCompatibilityTest method testContinuousQueries.
/**
*/
private void testContinuousQueries() throws Exception {
X.println(">>>> Testing continuous queries");
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
ClientCache<Object, Object> cache = client.getOrCreateCache("testContinuousQueries");
List<CacheEntryEvent<?, ?>> allEvts = new ArrayList<>();
cache.query(new ContinuousQuery<>().setLocalListener(evts -> evts.forEach(allEvts::add)));
cache.put(0, 0);
cache.put(0, 1);
cache.remove(0);
assertTrue(GridTestUtils.waitForCondition(() -> allEvts.size() == 3, 1_000L));
}
}
use of org.apache.ignite.client.ClientCache in project ignite by apache.
the class CacheEntryListenersTest method testJCacheListeners.
/**
* Test JCache entry listeners.
*/
@Test
public void testJCacheListeners() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testJCacheListeners");
JCacheEntryListener<Integer, Integer> lsnr = new JCacheEntryListener<>();
cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr, null, true, false));
for (int i = 0; i < 10; i++) cache.put(i, i);
assertEquals(F.asMap(EventType.CREATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.put(i, -i);
assertEquals(F.asMap(EventType.UPDATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.remove(i);
assertEquals(F.asMap(EventType.REMOVED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
assertTrue(lsnr.isQueueEmpty());
}
}
use of org.apache.ignite.client.ClientCache in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueries.
/**
* Test continuous queries.
*/
@Test
public void testContinuousQueries() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQ");
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr));
for (int i = 0; i < 10; i++) cache.put(i, i);
assertEquals(F.asMap(EventType.CREATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.put(i, -i);
assertEquals(F.asMap(EventType.UPDATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.remove(i);
assertEquals(F.asMap(EventType.REMOVED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
assertTrue(lsnr.isQueueEmpty());
}
}
Aggregations