Search in sources :

Example 1 with CountMarshallingPojo

use of org.infinispan.test.data.CountMarshallingPojo in project infinispan by infinispan.

the class StoreAsBinaryTest method testStores.

/**
 * Run this on a separate cache as it creates and stops stores, which might affect other tests.
 */
public void testStores() {
    ConfigurationBuilder cacheCofig = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false);
    cacheCofig.memory().storageType(StorageType.BINARY);
    DummyInMemoryStoreConfigurationBuilder dimcs = new DummyInMemoryStoreConfigurationBuilder(cacheCofig.persistence());
    dimcs.storeName(getClass().getSimpleName());
    cacheCofig.persistence().addStore(dimcs);
    defineConfigurationOnAllManagers("replSync2", cacheCofig);
    waitForClusterToForm("replSync2");
    Cache<Object, Object> cache1 = cache(0, "replSync2");
    Cache<Object, Object> cache2 = cache(1, "replSync2");
    CountMarshallingPojo pojo = new CountMarshallingPojo(POJO_NAME, 1);
    cache1.put("key", pojo);
    assertEquals(pojo, cache2.get("key"));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)

Example 2 with CountMarshallingPojo

use of org.infinispan.test.data.CountMarshallingPojo in project infinispan by infinispan.

the class StoreAsBinaryTest method testReleaseObjectKeyReferences.

public void testReleaseObjectKeyReferences() {
    Cache<Object, String> cache1 = cache(0, "replSync");
    Cache<Object, String> cache2 = cache(1, "replSync");
    CountMarshallingPojo key = new CountMarshallingPojo(POJO_NAME, 1);
    cache1.put(key, "value");
    DataContainer<Object, String> dc1 = extractComponent(cache1, InternalDataContainer.class);
    Object firstKeyStorage = dc1.iterator().next().getKey();
    Object firstKey = cache1.getAdvancedCache().getKeyDataConversion().fromStorage(firstKeyStorage);
    assertEquals(key, firstKey);
    assertEquals("value", cache1.get(key));
    // now on cache 2
    DataContainer<Object, String> dc2 = extractComponent(cache2, InternalDataContainer.class);
    firstKeyStorage = dc2.iterator().next().getKey();
    firstKey = cache1.getAdvancedCache().getKeyDataConversion().fromStorage(firstKeyStorage);
    assertEquals(key, firstKey);
    assertEquals("value", cache2.get(key));
}
Also used : CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo)

Example 3 with CountMarshallingPojo

use of org.infinispan.test.data.CountMarshallingPojo in project infinispan by infinispan.

the class StoreAsBinaryTest method testCallbackValues.

public void testCallbackValues() throws Exception {
    Cache<Object, Object> cache1 = cache(0, "replSync");
    cache(1, "replSync");
    MockListener l = new MockListener();
    cache1.addListener(l);
    try {
        CountMarshallingPojo pojo = new CountMarshallingPojo(POJO_NAME, 1);
        cache1.put("key", pojo);
        assertTrue("received " + l.newValue.getClass().getName(), l.newValue instanceof CountMarshallingPojo);
    } finally {
        cache1.removeListener(l);
    }
}
Also used : CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo)

Example 4 with CountMarshallingPojo

use of org.infinispan.test.data.CountMarshallingPojo in project infinispan by infinispan.

the class MarshalledValuesManualEvictionTest method testManualEvictCustomKeyValue.

public void testManualEvictCustomKeyValue() {
    CountMarshallingPojo.reset(POJO_NAME);
    CountMarshallingPojo p1 = new CountMarshallingPojo(POJO_NAME, 64);
    CountMarshallingPojo p2 = new CountMarshallingPojo(POJO_NAME, 24);
    CountMarshallingPojo p3 = new CountMarshallingPojo(POJO_NAME, 97);
    CountMarshallingPojo p4 = new CountMarshallingPojo(POJO_NAME, 35);
    // 2 writes, key & value
    cache.put(p1, p2);
    // 2 writes, key & value
    cache.put(p3, p4);
    assertEquals(2, cache.size());
    // 1 write
    cache.evict(p1);
    assertEquals(1, cache.size());
    // 1 write, 1 read
    assertEquals(p4, cache.get(p3));
    assertEquals(6, CountMarshallingPojo.getMarshallCount(POJO_NAME));
    assertEquals(1, CountMarshallingPojo.getUnmarshallCount(POJO_NAME));
}
Also used : CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo)

Example 5 with CountMarshallingPojo

use of org.infinispan.test.data.CountMarshallingPojo in project infinispan by infinispan.

the class MarshalledValuesManualEvictionTest method testEvictPrimitiveKeyCustomValue.

public void testEvictPrimitiveKeyCustomValue() {
    CountMarshallingPojo.reset(POJO_NAME);
    CountMarshallingPojo p1 = new CountMarshallingPojo(POJO_NAME, 51);
    CountMarshallingPojo p2 = new CountMarshallingPojo(POJO_NAME, 78);
    // 1 write
    cache.put("key-isoprene", p1);
    // 1 write
    cache.put("key-hexastyle", p2);
    assertEquals(2, cache.size());
    cache.evict("key-isoprene");
    assertEquals(1, cache.size());
    // 1 read
    assertEquals(p2, cache.get("key-hexastyle"));
    assertEquals(2, CountMarshallingPojo.getMarshallCount(POJO_NAME));
    assertEquals(1, CountMarshallingPojo.getUnmarshallCount(POJO_NAME));
}
Also used : CountMarshallingPojo(org.infinispan.test.data.CountMarshallingPojo)

Aggregations

CountMarshallingPojo (org.infinispan.test.data.CountMarshallingPojo)14 WrappedByteArray (org.infinispan.commons.marshall.WrappedByteArray)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StreamingMarshaller (org.infinispan.commons.marshall.StreamingMarshaller)1 WrappedBytes (org.infinispan.commons.marshall.WrappedBytes)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)1 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)1 TestingUtil.createMapEntry (org.infinispan.test.TestingUtil.createMapEntry)1