try {
System.setProperty("tangosol.coherence.distributed.localstorage", "false");
System.setProperty("tangosol.coherence.cacheconfig", "event-benchmark-cache-config.xml");
final NamedCache p1 = CacheFactory.getCache("pool-1");
final NamedCache p2 = CacheFactory.getCache("pool-2");
final NamedCache p3 = CacheFactory.getCache("pool-3");
final NamedCache p4 = CacheFactory.getCache("pool-4");
p1.clear();
p2.clear();
p3.clear();
p4.clear();
long objectCount = 50000;
final int batchSize = 20;
int threadCount = 4;
final Object value = new String[]{"ABC", "EFG", "123", "890", "QWERTY"};
p1.addMapListener(new MapListener() {
@Override
public void entryUpdated(MapEvent evt) {
}
@Override
public void entryInserted(MapEvent evt) {
p4.put(evt.getKey(), evt.getNewValue());
}
@Override
public void entryDeleted(MapEvent evt) {
}
});
p2.addMapListener(new MapListener() {
@Override
public void entryUpdated(MapEvent evt) {
}
@Override
public void entryInserted(MapEvent evt) {
p3.put(evt.getKey(), evt.getNewValue());
}
@Override
public void entryDeleted(MapEvent evt) {
}
});
p3.addMapListener(new MapListener() {
@Override
public void entryUpdated(MapEvent evt) {
}
@Override
public void entryInserted(MapEvent evt) {
p4.put(evt.getKey(), evt.getNewValue());
}
@Override
public void entryDeleted(MapEvent evt) {
}
});
ExecutorService service = Executors.newFixedThreadPool(threadCount);
Thread.sleep(500);
System.out.println("Start test");
long startTimestamp = System.nanoTime();
for(long i = 0; i != objectCount; i += batchSize) {
final Long key = Long.valueOf(i);
service.execute(new Runnable() {
@Override
public void run() {
if (batchSize == 1) {
p1.put(key, value);
}
else {
Map<Long, Object> batch = new HashMap<Long, Object>();
for(int j = 0; j != batchSize; ++j) {
batch.put(key + j, value);
}
p1.putAll(batch);
}
}
});
}
service.shutdown();
service.awaitTermination(60, TimeUnit.SECONDS);
System.out.println("Wait for cache");
while(true) {
if (p4.size() == objectCount) {
break;
}
else {
Thread.sleep(1);
}