use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class IgniteCacheBinaryEntryProcessorSelfTest method checkInvokeBinaryObject.
/**
* @param cacheMode Cache mode to test.
* @param atomicityMode Atomicity mode to test.
* @throws Exception
*/
private void checkInvokeBinaryObject(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
Ignite client = ignite(SRV_CNT);
IgniteCache<Integer, TestValue> clientCache = client.createCache(cacheConfiguration(cacheMode, atomicityMode));
try {
IgniteBinary binary = client.binary();
for (int i = 0; i < 100; i++) {
clientCache.put(i, new TestValue(i, "value-" + i));
BinaryObjectBuilder bldr = binary.builder("NoClass");
bldr.setField("val", i);
bldr.setField("strVal", "value-" + i);
clientCache.withKeepBinary().put(-(i + 1), bldr.build());
}
IgniteCache<Integer, BinaryObject> binaryClientCache = clientCache.withKeepBinary();
for (int i = 0; i < 100; i++) {
binaryClientCache.invoke(i, new TestEntryProcessor());
binaryClientCache.invoke(-(i + 1), new TestEntryProcessor());
}
for (int g = 0; g < NODES; g++) {
IgniteCache<Integer, TestValue> nodeCache = ignite(g).cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, BinaryObject> nodeBinaryCache = nodeCache.withKeepBinary();
for (int i = 0; i < 100; i++) {
TestValue updated = nodeCache.get(i);
assertEquals((Integer) (i + 1), updated.value());
assertEquals("updated-" + i, updated.stringValue());
BinaryObject updatedBinary = nodeBinaryCache.get(i);
assertEquals(new Integer(i + 1), updatedBinary.field("val"));
assertEquals("updated-" + i, updatedBinary.field("strVal"));
updatedBinary = nodeBinaryCache.get(-(i + 1));
assertEquals(new Integer(i + 1), updatedBinary.field("val"));
assertEquals("updated-" + i, updatedBinary.field("strVal"));
}
}
} finally {
client.destroyCache(DEFAULT_CACHE_NAME);
}
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientStartsFirst.
/**
* @throws Exception If failed.
*/
public void testClientStartsFirst() throws Exception {
client = true;
final Ignite ignite0 = startGrid(0);
assertTrue(ignite0.configuration().isClientMode());
client = false;
Ignite ignite1 = startGrid(1);
assertFalse(ignite1.configuration().isClientMode());
IgniteBinary binaries = ignite(1).binary();
IgniteCache<Object, Object> cache = ignite(1).cache(DEFAULT_CACHE_NAME).withKeepBinary();
for (int i = 0; i < 100; i++) {
BinaryObjectBuilder builder = binaries.builder("type-" + i);
builder.setField("f0", i);
cache.put(i, builder.build());
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite0.binary().types().size() == 100;
}
}, 5000);
assertEquals(100, ignite(0).binary().types().size());
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientMetadataInitialization.
/**
* @throws Exception If failed.
*/
public void testClientMetadataInitialization() throws Exception {
startGrids(2);
final AtomicBoolean stop = new AtomicBoolean();
final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
IgniteInternalFuture<?> fut;
try {
// Update binary metadata concurrently with client nodes start.
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteBinary binaries = ignite(0).binary();
IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 1000; i++) {
log.info("Iteration: " + i);
String type = "binary-type-" + i;
allTypes.add(type);
for (int f = 0; f < 10; f++) {
BinaryObjectBuilder builder = binaries.builder(type);
String fieldName = "f" + f;
builder.setField(fieldName, i);
cache.put(rnd.nextInt(0, 100_000), builder.build());
if (f % 100 == 0)
log.info("Put iteration: " + f);
}
if (stop.get())
break;
}
return null;
}
}, 5, "update-thread");
} finally {
stop.set(true);
}
client = true;
startGridsMultiThreaded(2, 5);
fut.get();
assertFalse(allTypes.isEmpty());
log.info("Expected binary types: " + allTypes.size());
assertEquals(7, ignite(0).cluster().nodes().size());
for (int i = 0; i < 7; i++) {
log.info("Check metadata on node: " + i);
boolean client = i > 1;
assertEquals((Object) client, ignite(i).configuration().isClientMode());
IgniteBinary binaries = ignite(i).binary();
Collection<BinaryType> metaCol = binaries.types();
assertEquals(allTypes.size(), metaCol.size());
Set<String> names = new HashSet<>();
for (BinaryType meta : metaCol) {
info("Binary type: " + meta);
assertTrue(names.add(meta.typeName()));
assertNull(meta.affinityKeyFieldName());
assertEquals(10, meta.fieldNames().size());
}
assertEquals(allTypes.size(), names.size());
}
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class JdbcResultSetSelfTest method testObject.
/**
* @throws Exception If failed.
*/
public void testObject() throws Exception {
final Ignite ignite = ignite(0);
final boolean binaryMarshaller = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
final IgniteBinary binary = binaryMarshaller ? ignite.binary() : null;
ResultSet rs = stmt.executeQuery(SQL);
TestObjectField f1 = new TestObjectField(100, "AAAA");
TestObjectField f2 = new TestObjectField(500, "BBBB");
TestObject o = createObjectWithData(1);
assertTrue(rs.next());
assertEqualsToStringRepresentation(f1, binary, rs.getObject("f1"));
assertEqualsToStringRepresentation(f1, binary, rs.getObject(16));
assertEqualsToStringRepresentation(f2, binary, rs.getObject("f2"));
assertEqualsToStringRepresentation(f2, binary, rs.getObject(17));
assertNull(rs.getObject("f3"));
assertTrue(rs.wasNull());
assertNull(rs.getObject(18));
assertTrue(rs.wasNull());
assertEqualsToStringRepresentation(o, binary, rs.getObject("_val"));
assertEqualsToStringRepresentation(o, binary, rs.getObject(19));
assertFalse(rs.next());
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class JdbcResultSetSelfTest method testObject.
/**
* @throws Exception If failed.
*/
public void testObject() throws Exception {
final Ignite ignite = ignite(0);
final boolean binaryMarshaller = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
final IgniteBinary binary = binaryMarshaller ? ignite.binary() : null;
ResultSet rs = stmt.executeQuery(SQL);
TestObjectField f1 = new TestObjectField(100, "AAAA");
TestObjectField f2 = new TestObjectField(500, "BBBB");
TestObject o = createObjectWithData(1);
assertTrue(rs.next());
assertEqualsToStringRepresentation(f1, binary, rs.getObject("f1"));
assertEqualsToStringRepresentation(f1, binary, rs.getObject(16));
assertEqualsToStringRepresentation(f2, binary, rs.getObject("f2"));
assertEqualsToStringRepresentation(f2, binary, rs.getObject(17));
assertNull(rs.getObject("f3"));
assertTrue(rs.wasNull());
assertNull(rs.getObject(18));
assertTrue(rs.wasNull());
assertEqualsToStringRepresentation(o, binary, rs.getObject("_val"));
assertEqualsToStringRepresentation(o, binary, rs.getObject(19));
assertFalse(rs.next());
}
Aggregations