Search in sources :

Example 1 with ClientCacheConfiguration

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());
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) QueryEntity(org.apache.ignite.cache.QueryEntity) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 2 with ClientCacheConfiguration

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;
}
Also used : ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 3 with ClientCacheConfiguration

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[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientTransaction(org.apache.ignite.client.ClientTransaction) ClientTransactionConfiguration(org.apache.ignite.configuration.ClientTransactionConfiguration) ClientCache(org.apache.ignite.client.ClientCache) ClientTransactions(org.apache.ignite.client.ClientTransactions) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with ClientCacheConfiguration

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);
    }
}
Also used : Path(java.nio.file.Path) IgniteClient(org.apache.ignite.client.IgniteClient) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) Test(org.junit.Test)

Example 5 with ClientCacheConfiguration

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();
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) IgniteException(org.apache.ignite.IgniteException) ClientTransaction(org.apache.ignite.client.ClientTransaction) Ignite(org.apache.ignite.Ignite) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) IgniteException(org.apache.ignite.IgniteException) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Aggregations

ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)17 IgniteClient (org.apache.ignite.client.IgniteClient)12 Test (org.junit.Test)9 Collection (java.util.Collection)6 Map (java.util.Map)6 Objects (java.util.Objects)6 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)6 ClientCache (org.apache.ignite.client.ClientCache)5 ClientException (org.apache.ignite.client.ClientException)5 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collections (java.util.Collections)4 CancellationException (java.util.concurrent.CancellationException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)4 CachePeekMode (org.apache.ignite.cache.CachePeekMode)4 IgniteClientFuture (org.apache.ignite.client.IgniteClientFuture)4 Person (org.apache.ignite.client.Person)4 PersonBinarylizable (org.apache.ignite.client.PersonBinarylizable)4