use of org.infinispan.commons.marshall.WrappedBytes in project infinispan by infinispan.
the class OffHeapBoundedSingleNodeStressTest method testLotsOfPutsAndReadsIntoDataContainer.
public void testLotsOfPutsAndReadsIntoDataContainer() throws InterruptedException, ExecutionException {
int WRITE_THREADS = 4;
int READ_THREADS = 16;
ExecutorService execService = Executors.newFixedThreadPool(WRITE_THREADS + READ_THREADS, getTestThreadFactory("Worker"));
ExecutorCompletionService<Void> service = new ExecutorCompletionService<>(execService);
try {
Cache<WrappedBytes, WrappedBytes> cache = cache(0);
final DataContainer<WrappedBytes, WrappedBytes> map = cache.getAdvancedCache().getDataContainer();
for (int i = 0; i < WRITE_THREADS; ++i) {
service.submit(() -> {
KeyGenerator generator = new KeyGenerator();
while (!Thread.interrupted()) {
WrappedByteArray key = generator.getNextKey();
WrappedByteArray value = generator.getNextValue();
map.put(key, value, generator.getMetadata());
}
return null;
});
}
for (int i = 0; i < READ_THREADS; ++i) {
service.submit(() -> {
KeyGenerator generator = new KeyGenerator();
while (!Thread.interrupted()) {
WrappedByteArray key = generator.getNextKey();
InternalCacheEntry<WrappedBytes, WrappedBytes> innerV = map.get(key);
// Here just to make sure get doesn't get optimized away
if (innerV != null && innerV.equals(cache)) {
System.out.println(System.currentTimeMillis());
}
}
return null;
});
}
// This is how long this test will run for
Future<Void> future = service.poll(30, TimeUnit.SECONDS);
if (future != null) {
future.get();
}
} finally {
execService.shutdownNow();
execService.awaitTermination(10, TimeUnit.SECONDS);
}
}
use of org.infinispan.commons.marshall.WrappedBytes in project infinispan by infinispan.
the class OffHeapConcurrentMapTest method putInMap.
WrappedBytes putInMap(OffHeapConcurrentMap map, WrappedBytes value) {
InternalCacheEntry<WrappedBytes, WrappedBytes> ice;
WrappedBytes key;
do {
key = randomBytes();
ice = map.put(key, new ImmortalCacheEntry(key, value));
} while (ice != null);
return key;
}
use of org.infinispan.commons.marshall.WrappedBytes in project infinispan by infinispan.
the class StoreAsBinaryTest method testEqualsAndHashCode.
public void testEqualsAndHashCode() throws Exception {
StreamingMarshaller marshaller = extractGlobalMarshaller(manager(0));
CountMarshallingPojo pojo = new CountMarshallingPojo(POJO_NAME, 1);
WrappedBytes wb = new WrappedByteArray(marshaller.objectToByteBuffer(pojo));
WrappedBytes wb2 = new WrappedByteArray(marshaller.objectToByteBuffer(pojo));
assertEquals(wb2.hashCode(), wb.hashCode());
assertEquals(wb, wb2);
}
Aggregations