Search in sources :

Example 1 with NumericVersion

use of org.infinispan.container.versioning.NumericVersion in project infinispan by infinispan.

the class MetaParamsTest method testDuplicateParametersOnConstruction.

@Test
public void testDuplicateParametersOnConstruction() {
    MetaEntryVersion versionParam1 = new MetaEntryVersion(new NumericVersion(100));
    MetaEntryVersion versionParam2 = new MetaEntryVersion(new NumericVersion(200));
    MetaParams metas = MetaParams.of(versionParam1, versionParam2);
    assertEquals(1, metas.size());
    assertEquals(Optional.of(new MetaEntryVersion(new NumericVersion(200))), metas.find(MetaEntryVersion.class));
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) MetaEntryVersion(org.infinispan.functional.MetaParam.MetaEntryVersion) Test(org.testng.annotations.Test)

Example 2 with NumericVersion

use of org.infinispan.container.versioning.NumericVersion in project infinispan by infinispan.

the class OffHeapBoundedMemoryTest method testAllocatedAmountEqualWithVersionAndExpiration.

public void testAllocatedAmountEqualWithVersionAndExpiration() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.memory().size(MemoryUnit.MEGABYTES.toBytes(20)).evictionType(EvictionType.MEMORY).storageType(StorageType.OFF_HEAP);
    EmbeddedCacheManager manager = TestCacheManagerFactory.createCacheManager(builder);
    AdvancedCache<Object, Object> cache = manager.getCache().getAdvancedCache();
    cache.put("lifespan", 2, new EmbeddedMetadata.Builder().lifespan(1, TimeUnit.MINUTES).version(new NumericVersion(23)).build());
    cache.put("both", 2, new EmbeddedMetadata.Builder().lifespan(1, TimeUnit.MINUTES).maxIdle(1, TimeUnit.MINUTES).version(new NumericVersion(23)).build());
    cache.put("maxidle", 2, new EmbeddedMetadata.Builder().maxIdle(1, TimeUnit.MINUTES).version(new NumericVersion(23)).build());
    OffHeapMemoryAllocator allocator = cache.getComponentRegistry().getComponent(OffHeapMemoryAllocator.class);
    BoundedOffHeapDataContainer container = (BoundedOffHeapDataContainer) getContainer(cache);
    assertEquals(allocator.getAllocatedAmount(), container.currentSize);
    cache.clear();
    assertEquals(allocator.getAllocatedAmount(), container.currentSize);
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 3 with NumericVersion

use of org.infinispan.container.versioning.NumericVersion in project infinispan by infinispan.

the class OffHeapBoundedMemoryTest method testAllocatedAmountEqualWithVersion.

public void testAllocatedAmountEqualWithVersion() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.memory().size(MemoryUnit.MEGABYTES.toBytes(20)).evictionType(EvictionType.MEMORY).storageType(StorageType.OFF_HEAP);
    EmbeddedCacheManager manager = TestCacheManagerFactory.createCacheManager(builder);
    AdvancedCache<Object, Object> cache = manager.getCache().getAdvancedCache();
    cache.put(1, 2, new EmbeddedMetadata.Builder().version(new NumericVersion(23)).build());
    OffHeapMemoryAllocator allocator = cache.getComponentRegistry().getComponent(OffHeapMemoryAllocator.class);
    BoundedOffHeapDataContainer container = (BoundedOffHeapDataContainer) getContainer(cache);
    assertEquals(allocator.getAllocatedAmount(), container.currentSize);
    cache.clear();
    assertEquals(allocator.getAllocatedAmount(), container.currentSize);
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 4 with NumericVersion

use of org.infinispan.container.versioning.NumericVersion in project infinispan by infinispan.

the class HotRodClientTestingUtil method entryVersion.

public static <K> long entryVersion(Cache<byte[], ?> cache, K key) {
    byte[] lookupKey;
    try {
        lookupKey = toBytes(key);
    } catch (Exception e) {
        throw new AssertionError(e);
    }
    Metadata meta = cache.getAdvancedCache().getCacheEntry(lookupKey).getMetadata();
    return ((NumericVersion) meta.version()).getVersion();
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) Metadata(org.infinispan.metadata.Metadata) IOException(java.io.IOException)

Example 5 with NumericVersion

use of org.infinispan.container.versioning.NumericVersion in project infinispan by infinispan.

the class MetadataAPITest method testPutIfAbsentWithVersion.

public void testPutIfAbsentWithVersion() {
    final Integer key = 3;
    NumericVersion version = new NumericVersion(1);
    assertEquals(null, advCache.putIfAbsent(key, "v1", withVersion(version)));
    CacheEntry cacheEntry = advCache.getCacheEntry(key);
    assertEquals(EQUAL, version.compareTo(cacheEntry.getMetadata().version()));
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) CacheEntry(org.infinispan.container.entries.CacheEntry)

Aggregations

NumericVersion (org.infinispan.container.versioning.NumericVersion)26 CacheEntry (org.infinispan.container.entries.CacheEntry)10 Metadata (org.infinispan.metadata.Metadata)7 MetaEntryVersion (org.infinispan.functional.MetaParam.MetaEntryVersion)5 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)5 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)5 Set (java.util.Set)4 Test (org.testng.annotations.Test)4 ByteBuf (io.netty.buffer.ByteBuf)3 BitSet (java.util.BitSet)3 List (java.util.List)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionStage (java.util.concurrent.CompletionStage)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AdvancedCache (org.infinispan.AdvancedCache)3 EntryVersion (org.infinispan.container.versioning.EntryVersion)3 Flag (org.infinispan.context.Flag)3 Channel (io.netty.channel.Channel)2 IOException (java.io.IOException)2