use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class ClientUtils method cacheConfiguration.
/**
* Deserialize configuration from stream.
*/
ClientCacheConfiguration cacheConfiguration(BinaryInputStream in, ProtocolContext protocolCtx) throws IOException {
try (BinaryReaderExImpl reader = createBinaryReader(in)) {
// Do not need length to read data. The protocol defines fixed configuration layout.
reader.readInt();
return // cache name is to be assigned later
new ClientCacheConfiguration().setName("TBD").setAtomicityMode(CacheAtomicityMode.fromOrdinal(reader.readInt())).setBackups(reader.readInt()).setCacheMode(CacheMode.fromOrdinal(reader.readInt())).setCopyOnRead(reader.readBoolean()).setDataRegionName(reader.readString()).setEagerTtl(reader.readBoolean()).setStatisticsEnabled(reader.readBoolean()).setGroupName(reader.readString()).setDefaultLockTimeout(reader.readLong()).setMaxConcurrentAsyncOperations(reader.readInt()).setMaxQueryIteratorsCount(reader.readInt()).setName(reader.readString()).setOnheapCacheEnabled(reader.readBoolean()).setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte) reader.readInt())).setQueryDetailMetricsSize(reader.readInt()).setQueryParallelism(reader.readInt()).setReadFromBackup(reader.readBoolean()).setRebalanceBatchSize(reader.readInt()).setRebalanceBatchesPrefetchCount(reader.readLong()).setRebalanceDelay(reader.readLong()).setRebalanceMode(CacheRebalanceMode.fromOrdinal(reader.readInt())).setRebalanceOrder(reader.readInt()).setRebalanceThrottle(reader.readLong()).setRebalanceTimeout(reader.readLong()).setSqlEscapeAll(reader.readBoolean()).setSqlIndexMaxInlineSize(reader.readInt()).setSqlSchema(reader.readString()).setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(reader.readInt())).setKeyConfiguration(ClientUtils.collection(in, unused -> new CacheKeyConfiguration(reader.readString(), reader.readString())).toArray(new CacheKeyConfiguration[0])).setQueryEntities(ClientUtils.collection(in, unused -> {
QueryEntity qryEntity = new QueryEntity(reader.readString(), reader.readString()).setTableName(reader.readString()).setKeyFieldName(reader.readString()).setValueFieldName(reader.readString());
boolean isPrecisionAndScaleSupported = protocolCtx.isFeatureSupported(QUERY_ENTITY_PRECISION_AND_SCALE);
Collection<QueryField> qryFields = ClientUtils.collection(in, unused2 -> {
String name = reader.readString();
String typeName = reader.readString();
boolean isKey = reader.readBoolean();
boolean isNotNull = reader.readBoolean();
Object dfltVal = reader.readObject();
int precision = isPrecisionAndScaleSupported ? reader.readInt() : -1;
int scale = isPrecisionAndScaleSupported ? reader.readInt() : -1;
return new QueryField(name, typeName, isKey, isNotNull, dfltVal, precision, scale);
});
return qryEntity.setFields(qryFields.stream().collect(Collectors.toMap(QueryField::getName, QueryField::getTypeName, (a, b) -> a, LinkedHashMap::new))).setKeyFields(qryFields.stream().filter(QueryField::isKey).map(QueryField::getName).collect(Collectors.toCollection(LinkedHashSet::new))).setNotNullFields(qryFields.stream().filter(QueryField::isNotNull).map(QueryField::getName).collect(Collectors.toSet())).setDefaultFieldValues(qryFields.stream().filter(f -> f.getDefaultValue() != null).collect(Collectors.toMap(QueryField::getName, QueryField::getDefaultValue))).setFieldsPrecision(qryFields.stream().filter(f -> f.getPrecision() != -1).collect(Collectors.toMap(QueryField::getName, QueryField::getPrecision))).setFieldsScale(qryFields.stream().filter(f -> f.getScale() != -1).collect(Collectors.toMap(QueryField::getName, QueryField::getScale))).setAliases(ClientUtils.collection(in, unused3 -> new SimpleEntry<>(reader.readString(), reader.readString())).stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue))).setIndexes(ClientUtils.collection(in, unused4 -> {
String name = reader.readString();
QueryIndexType type = QueryIndexType.fromOrdinal(reader.readByte());
int inlineSize = reader.readInt();
LinkedHashMap<String, Boolean> fields = ClientUtils.collection(in, unused5 -> new SimpleEntry<>(reader.readString(), reader.readBoolean())).stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new));
return new QueryIndex(fields, type).setName(name).setInlineSize(inlineSize);
}));
}).toArray(new QueryEntity[0])).setExpiryPolicy(!protocolCtx.isFeatureSupported(EXPIRY_POLICY) ? null : reader.readBoolean() ? new PlatformExpiryPolicy(reader.readLong(), reader.readLong(), reader.readLong()) : null);
}
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class CacheAsyncTest method testGetOrCreateCacheAsyncByNameReturnsExistingWhenCacheExists.
/**
* Tests async cache creation with existing name.
*/
@Test
public void testGetOrCreateCacheAsyncByNameReturnsExistingWhenCacheExists() throws Exception {
ClientCacheConfiguration cfg = new ClientCacheConfiguration().setName(TMP_CACHE_NAME).setBackups(7);
client.createCache(cfg);
ClientCache<Object, Object> cache = client.getOrCreateCacheAsync(TMP_CACHE_NAME).get();
ClientCacheConfiguration resCfg = cache.getConfigurationAsync().get();
assertEquals(7, resCfg.getBackups());
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class CacheAsyncTest method testCreateCacheAsyncByCfgThrowsExceptionWhenCacheExists.
/**
* Tests async cache creation with existing name.
*/
@Test
public void testCreateCacheAsyncByCfgThrowsExceptionWhenCacheExists() throws Exception {
client.createCache(TMP_CACHE_NAME);
ClientCacheConfiguration cfg = new ClientCacheConfiguration().setName(TMP_CACHE_NAME).setBackups(3);
Throwable t = client.createCacheAsync(cfg).handle((res, err) -> err).toCompletableFuture().get().getCause();
assertEquals(ClientException.class, t.getClass());
assertTrue(t.getMessage(), t.getMessage().contains("Failed to start cache (a cache with the same name is already started): tmp_cache"));
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class CacheAsyncTest method testCreateCacheAsyncByCfgCreatesCacheWhenNotExists.
/**
* Tests async cache creation.
*/
@Test
public void testCreateCacheAsyncByCfgCreatesCacheWhenNotExists() throws Exception {
ClientCacheConfiguration cfg = new ClientCacheConfiguration().setName(TMP_CACHE_NAME).setBackups(3).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
assertTrue(client.createCacheAsync(cfg).thenApply(x -> client.cacheNames().contains(TMP_CACHE_NAME)).toCompletableFuture().get());
ClientCacheConfiguration resCfg = client.cache(TMP_CACHE_NAME).getConfiguration();
assertEquals(3, resCfg.getBackups());
assertEquals(CacheAtomicityMode.TRANSACTIONAL, resCfg.getAtomicityMode());
}
use of org.apache.ignite.client.ClientCacheConfiguration in project ignite by apache.
the class ClientSizeCacheCreationDestructionTest method createCache.
/**
* Create cache with specified configuration through thin/thick client or jdbc thin.
*
* @param node Cluster node or jdbc connection.
* @param cacheCfg Cache or ClientCache configuration
* @throws SQLException If failed to create cache through Jdbc Thin connection.
*/
private void createCache(AutoCloseable node, Serializable cacheCfg) throws SQLException {
if (node instanceof IgniteClient)
((IgniteClient) node).createCache((ClientCacheConfiguration) cacheCfg);
else if (node instanceof Ignite)
((Ignite) node).createCache((CacheConfiguration) cacheCfg);
else if (node instanceof JdbcThinConnection) {
CacheConfiguration jdbcCacheCfg = (CacheConfiguration) cacheCfg;
srv.addCacheConfiguration(jdbcCacheCfg);
try (Statement stmt = jdbcConn.createStatement()) {
stmt.execute("CREATE TABLE " + jdbcCacheCfg.getName() + " (id int, name varchar, primary key (id)) WITH \"template=" + jdbcCacheCfg.getName() + "\"");
}
} else
fail(" Unexpected node/client type");
}
Aggregations