Search in sources :

Example 16 with WrappedBytes

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);
    }
}
Also used : WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) WrappedBytes(org.infinispan.commons.marshall.WrappedBytes) ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService)

Example 17 with WrappedBytes

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;
}
Also used : WrappedBytes(org.infinispan.commons.marshall.WrappedBytes) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry)

Example 18 with WrappedBytes

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);
}
Also used : CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo) WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) WrappedBytes(org.infinispan.commons.marshall.WrappedBytes) StreamingMarshaller(org.infinispan.commons.marshall.StreamingMarshaller)

Aggregations

WrappedBytes (org.infinispan.commons.marshall.WrappedBytes)18 WrappedByteArray (org.infinispan.commons.marshall.WrappedByteArray)6 StampedLock (java.util.concurrent.locks.StampedLock)5 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)3 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)3 Metadata (org.infinispan.metadata.Metadata)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 CacheException (org.infinispan.commons.CacheException)2 Marshaller (org.infinispan.commons.marshall.Marshaller)2 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 EntryVersion (org.infinispan.container.versioning.EntryVersion)2 DataConversion (org.infinispan.encoding.DataConversion)2 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)2 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)2 PrivateMetadata (org.infinispan.metadata.impl.PrivateMetadata)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)2 Key (org.infinispan.test.data.Key)2