use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class CacheQueryBuildValueTest method testBuilderAndQuery.
/**
* @throws Exception If failed.
*/
public void testBuilderAndQuery() throws Exception {
Ignite node = ignite(0);
final IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
IgniteBinary binary = node.binary();
BinaryObjectBuilder builder = binary.builder(TestBuilderValue.class.getName());
cache.put(0, builder.build());
builder.setField("iVal", 1);
cache.put(1, builder.build());
List<Cache.Entry<Object, Object>> entries = cache.query(new SqlQuery<>(TestBuilderValue.class, "true")).getAll();
assertEquals(2, entries.size());
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method testEnumObjectQuery.
/**
* JUnit.
*
* @throws Exception In case of error.
*/
public void testEnumObjectQuery() throws Exception {
final IgniteCache<Long, EnumObject> cache = jcache(Long.class, EnumObject.class);
for (long i = 0; i < 50; i++) cache.put(i, new EnumObject(i, i % 2 == 0 ? EnumType.TYPE_A : EnumType.TYPE_B));
assertEnumQry("type = ?", EnumType.TYPE_A, EnumType.TYPE_A, cache, 25);
assertEnumQry("type > ?", EnumType.TYPE_A, EnumType.TYPE_B, cache, 25);
assertEnumQry("type < ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
assertEnumQry("type != ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
assertEmptyEnumQry("type = ?", null, cache);
assertEmptyEnumQry("type > ?", EnumType.TYPE_B, cache);
assertEmptyEnumQry("type < ?", EnumType.TYPE_A, cache);
cache.put(50L, new EnumObject(50, null));
assertNoArgEnumQry("type is null", null, cache, 1);
assertAnyResTypeEnumQry("type is not null", cache, 50);
// Additional tests for binary enums.
IgniteBinary binary = ignite().binary();
if (binary != null) {
assertEnumQry("type = ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_A, cache, 25);
assertEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_B, cache, 25);
assertEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
assertEnumQry("type != ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
assertEmptyEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_B), cache);
assertEmptyEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_A), cache);
}
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class BinarySimpleNameTestPropertySelfTest method checkProperty.
/**
* @param expTypeName Type name.
* @throws Exception If failed.
*/
private void checkProperty(String expTypeName) throws Exception {
String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME);
try {
GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
IgniteBinary binary = startGrid().binary();
BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass");
BinaryObject bObj = builder.build();
assertEquals(expTypeName, bObj.type().typeName());
} finally {
if (marshBackup != null)
GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup);
}
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class CacheKeepBinaryTransactionTest method testBinaryPutGetContains.
/**
* @throws Exception If failed.
*/
public void testBinaryPutGetContains() throws Exception {
IgniteEx ignite = grid(0);
IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary();
try (Transaction tx = ignite.transactions().txStart()) {
IgniteBinary binary = ignite.binary();
BinaryObject key = binary.builder("test-key").setField("id", 1).build();
BinaryObject val = binary.builder("test-val").setField("id", 22).build();
cache.put(key, val);
assertTrue(cache.containsKey(key));
assertEquals(val, cache.get(key));
}
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testFailoverOnStart.
/**
* @throws Exception If failed.
*/
public void testFailoverOnStart() throws Exception {
startGrids(4);
IgniteBinary binaries = ignite(0).binary();
IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
for (int i = 0; i < 1000; i++) {
BinaryObjectBuilder builder = binaries.builder("type-" + i);
builder.setField("f0", i);
cache.put(i, builder.build());
}
client = true;
final CyclicBarrier barrier = new CyclicBarrier(6);
final AtomicInteger startIdx = new AtomicInteger(4);
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
barrier.await();
Ignite ignite = startGrid(startIdx.getAndIncrement());
assertTrue(ignite.configuration().isClientMode());
log.info("Started node: " + ignite.name());
return null;
}
}, 5, "start-thread");
barrier.await();
U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
for (int i = 0; i < 3; i++) stopGrid(i);
fut.get();
assertEquals(6, ignite(3).cluster().nodes().size());
for (int i = 3; i < 7; i++) {
log.info("Check metadata on node: " + i);
boolean client = i > 3;
assertEquals((Object) client, ignite(i).configuration().isClientMode());
binaries = ignite(i).binary();
final IgniteBinary p0 = binaries;
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
Collection<BinaryType> metaCol = p0.types();
return metaCol.size() == 1000;
}
}, getTestTimeout());
Collection<BinaryType> metaCol = binaries.types();
assertEquals(1000, metaCol.size());
Set<String> names = new HashSet<>();
for (BinaryType meta : metaCol) {
assertTrue(names.add(meta.typeName()));
assertNull(meta.affinityKeyFieldName());
assertEquals(1, meta.fieldNames().size());
}
assertEquals(1000, names.size());
}
}
Aggregations