use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class JavaThinCompatibilityTest method testCacheConfiguration.
/**
*/
private void testCacheConfiguration(boolean checkFieldsPrecessionAndScale, boolean checkExpiryPlc) throws Exception {
X.println(">>>> Testing cache configuration");
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
String cacheName = "testCacheConfiguration";
ClientCacheConfiguration ccfg = new ClientCacheConfiguration();
ccfg.setName(cacheName);
ccfg.setBackups(3);
ccfg.setGroupName("cache");
ccfg.setCacheMode(CacheMode.PARTITIONED);
QueryEntity qryEntity = new QueryEntity(int.class.getName(), "Entity").setTableName("ENTITY").setFields(new LinkedHashMap<>(F.asMap("id", Integer.class.getName(), "rate", Double.class.getName())));
if (checkFieldsPrecessionAndScale) {
qryEntity.setFieldsPrecision(F.asMap("rate", 5));
qryEntity.setFieldsScale(F.asMap("rate", 2));
}
ccfg.setQueryEntities(qryEntity);
if (checkExpiryPlc)
ccfg.setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30));
client.createCache(ccfg);
ClientCacheConfiguration ccfg1 = client.cache(cacheName).getConfiguration();
assertEquals(ccfg.getName(), ccfg1.getName());
assertEquals(ccfg.getBackups(), ccfg1.getBackups());
assertEquals(ccfg.getGroupName(), ccfg1.getGroupName());
assertEquals(ccfg.getCacheMode(), ccfg1.getCacheMode());
assertEquals(ccfg.getQueryEntities().length, ccfg1.getQueryEntities().length);
assertEquals(ccfg.getQueryEntities()[0].getTableName(), ccfg1.getQueryEntities()[0].getTableName());
assertEquals(ccfg.getQueryEntities()[0].getFields(), ccfg1.getQueryEntities()[0].getFields());
if (checkFieldsPrecessionAndScale) {
assertEquals(ccfg.getQueryEntities()[0].getFieldsPrecision(), ccfg1.getQueryEntities()[0].getFieldsPrecision());
assertEquals(ccfg.getQueryEntities()[0].getFieldsScale(), ccfg1.getQueryEntities()[0].getFieldsScale());
}
if (checkExpiryPlc) {
assertEquals(ccfg.getExpiryPolicy().getExpiryForCreation(), ccfg1.getExpiryPolicy().getExpiryForCreation());
assertEquals(ccfg.getExpiryPolicy().getExpiryForAccess(), ccfg1.getExpiryPolicy().getExpiryForAccess());
assertEquals(ccfg.getExpiryPolicy().getExpiryForUpdate(), ccfg1.getExpiryPolicy().getExpiryForUpdate());
}
}
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class JavaThinClient method createCache.
ClientCache<Integer, String> createCache(IgniteClient client) {
// tag::getOrCreateCache[]
ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName("References").setCacheMode(CacheMode.REPLICATED).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ClientCache<Integer, String> cache = client.getOrCreateCache(cacheCfg);
// end::getOrCreateCache[]
return cache;
}
use of org.apache.ignite.client.ClientCacheConfiguration 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.ClientCacheConfiguration in project ignite by apache.
the class GridCommandHandlerMetadataTest method testDropThinConnectionsOnRemove.
/**
* Check the all thin connections are dropped on the command '--meta remove' and '--meta update'.
* Steps:
* - opens thin client connection.
* - creates Type0 on thin client side.
* - removes type by cmd line util.
* - executes any command on thin client to detect disconnect.
* - creates Type0 on thin client side with other type of field (checks the type was removed).
*/
@Test
public void testDropThinConnectionsOnRemove() throws Exception {
Path typeFile = FS.getPath("type0.bin");
try (IgniteClient cli = Ignition.startClient(clientConfiguration())) {
createType(cli.binary(), "Type0", 1);
assertEquals(EXIT_CODE_OK, execute("--meta", "remove", "--typeName", "Type0", "--out", typeFile.toString()));
// Executes command to check disconnect / reconnect.
GridTestUtils.assertThrows(log, () -> cli.createCache(new ClientCacheConfiguration().setName("test")), Exception.class, null);
createType(cli.binary(), "Type0", "str");
} finally {
if (Files.exists(typeFile))
Files.delete(typeFile);
}
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class TimeoutTest method testClientTimeoutOnOperation.
/**
* Test client timeout on operation.
*/
@Test
@SuppressWarnings("ThrowableNotThrown")
public void testClientTimeoutOnOperation() throws Exception {
try (Ignite ignite = startGrid(0)) {
try (IgniteClient client = startClient(0)) {
ClientCache<Object, Object> cache = client.getOrCreateCache(new ClientCacheConfiguration().setName("cache").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
doSleep(TIMEOUT * 2);
// Should not fail if connection is idle.
cache.put(0, 0);
CyclicBarrier barrier = new CyclicBarrier(2);
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try (ClientTransaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(0, 0);
barrier.await(TIMEOUT * 2, TimeUnit.MILLISECONDS);
barrier.await(TIMEOUT * 2, TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new IgniteException(e);
}
});
// Wait for the key locked.
barrier.await(TIMEOUT * 2, TimeUnit.MILLISECONDS);
long ts0 = System.currentTimeMillis();
try (ClientTransaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
try {
GridTestUtils.assertThrowsWithCause(() -> cache.put(0, 0), ClientException.class);
} finally {
// To unlock another thread.
barrier.await(TIMEOUT * 2, TimeUnit.MILLISECONDS);
}
}
long ts1 = System.currentTimeMillis();
assertTrue("Unexpected timeout [ts0=" + ts0 + ", ts1=" + ts1 + ']', ts1 - ts0 >= TIMEOUT && ts1 - ts0 < TIMEOUT * 2);
fut.get();
}
}
}
Aggregations