use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryMetadataUpdatesFlowTest method testConcurrentMetadataUpdates.
/**
* @throws Exception If failed.
*/
public void testConcurrentMetadataUpdates() throws Exception {
startGrid(0);
final Ignite client = startGrid(getConfiguration("client").setClientMode(true));
final IgniteCache<Integer, Object> cache = client.cache(DEFAULT_CACHE_NAME).withKeepBinary();
int threadsNum = 10;
final int updatesNum = 2000;
List<IgniteInternalFuture> futs = new ArrayList<>();
for (int i = 0; i < threadsNum; i++) {
final int threadId = i;
IgniteInternalFuture fut = runAsync(new Runnable() {
@Override
public void run() {
try {
for (int j = 0; j < updatesNum; j++) {
BinaryObjectBuilder bob = client.binary().builder(BINARY_TYPE_NAME);
bob.setField("field" + j, threadId);
cache.put(threadId, bob.build());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, "updater-" + i);
futs.add(fut);
}
for (IgniteInternalFuture fut : futs) fut.get();
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method checkTransform.
/**
* @param key Key.
* @throws Exception If failed.
*/
private void checkTransform(Integer key) throws Exception {
log.info("Transform: " + key);
IgniteCache<Integer, BinaryObject> c = keepBinaryCache();
try {
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNull("Unexpected value: " + val, val);
return null;
}
});
jcache(0).put(key, new TestObject(1));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(1), val.field("val"));
Ignite ignite = e.unwrap(Ignite.class);
IgniteBinary binaries = ignite.binary();
BinaryObjectBuilder builder = binaries.builder(val);
builder.setField("val", 2);
e.setValue(builder.build());
return null;
}
});
BinaryObject obj = c.get(key);
assertEquals(new Integer(2), obj.field("val"));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(2), val.field("val"));
e.setValue(val);
return null;
}
});
obj = c.get(key);
assertEquals(new Integer(2), obj.field("val"));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(2), val.field("val"));
e.remove();
return null;
}
});
assertNull(c.get(key));
} finally {
c.remove(key);
}
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridDataStreamerImplSelfTest method testAddBinaryCreatedWithBuilder.
/**
* Tries to propagate cache with binary objects created using the builder.
*
* @throws Exception If failed.
*/
public void testAddBinaryCreatedWithBuilder() throws Exception {
try {
binaries = true;
startGrids(2);
awaitPartitionMapExchange();
Ignite g0 = grid(0);
IgniteDataStreamer<Integer, BinaryObject> dataLdr = g0.dataStreamer(DEFAULT_CACHE_NAME);
for (int i = 0; i < 500; i++) {
BinaryObjectBuilder obj = g0.binary().builder("NoExistedClass");
obj.setField("id", i);
obj.setField("name", String.valueOf("name = " + i));
dataLdr.addData(i, obj.build());
}
dataLdr.close(false);
assertEquals(500, g0.cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
assertEquals(500, grid(1).cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
} finally {
G.stopAll(true);
}
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method addStringField.
/**
* Adds field of String type to fixed binary type.
*
* @param ignite Ignite.
* @param fieldName Field name.
* @param fieldVal Field value.
* @param cacheIdx Cache index.
*/
private void addStringField(Ignite ignite, String fieldName, String fieldVal, int cacheIdx) {
BinaryObjectBuilder builder = ignite.binary().builder(BINARY_TYPE_NAME);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME).withKeepBinary();
builder.setField(fieldName, fieldVal);
cache.put(cacheIdx, builder.build());
}
use of org.apache.ignite.binary.BinaryObjectBuilder 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