Search in sources :

Example 6 with Person

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

the class BaseStoreTest method testLoadAndStoreBytesValues.

public void testLoadAndStoreBytesValues() throws PersistenceException, IOException, InterruptedException {
    assertIsEmpty();
    SerializationContext ctx = ProtobufUtil.newSerializationContext();
    SerializationContextInitializer sci = TestDataSCI.INSTANCE;
    sci.registerSchema(ctx);
    sci.registerMarshallers(ctx);
    Marshaller userMarshaller = new ProtoStreamMarshaller(ctx);
    WrappedBytes key = new WrappedByteArray(userMarshaller.objectToByteBuffer(new Key("key")));
    WrappedBytes key2 = new WrappedByteArray(userMarshaller.objectToByteBuffer(new Key("key2")));
    WrappedBytes value = new WrappedByteArray(userMarshaller.objectToByteBuffer(new Person()));
    assertFalse(cl.contains(key));
    PersistenceMarshaller persistenceMarshaller = getMarshaller();
    cl.write(MarshalledEntryUtil.create(key, value, persistenceMarshaller));
    assertEquals(value, cl.loadEntry(key).getValue());
    MarshallableEntry entry = cl.loadEntry(key);
    assertTrue("Expected an immortalEntry", entry.getMetadata() == null || entry.expiryTime() == -1 || entry.getMetadata().maxIdle() == -1);
    assertContains(key, true);
    assertFalse(cl.delete(key2));
    assertTrue(cl.delete(key));
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) WrappedBytes(org.infinispan.commons.marshall.WrappedBytes) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) Person(org.infinispan.test.data.Person) Key(org.infinispan.test.data.Key)

Example 7 with Person

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

the class MultimapTestUtils method assertContaisKeyValue.

public static void assertContaisKeyValue(MultimapCache<String, Person> multimapCache, String key, Person value) {
    Address address = ((EmbeddedMultimapCache) multimapCache).getCache().getCacheManager().getAddress();
    await(multimapCache.get(key).thenAccept(v -> {
        assertTrue(format("get method call : multimap '%s' must contain key '%s' value '%s' pair", address, key, value), v.contains(value));
    }));
    await(multimapCache.containsEntry(key, value).thenAccept(v -> {
        assertTrue(format("containsEntry method call : multimap '%s' must contain key '%s' value '%s' pair", address, key, value), v);
    }));
}
Also used : MultimapCache(org.infinispan.multimap.api.embedded.MultimapCache) Person(org.infinispan.test.data.Person) Map(java.util.Map) FunctionalTestUtils.await(org.infinispan.functional.FunctionalTestUtils.await) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) TransactionManager(javax.transaction.TransactionManager) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) String.format(java.lang.String.format) Address(org.infinispan.remoting.transport.Address) Address(org.infinispan.remoting.transport.Address)

Example 8 with Person

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

the class TxDistributedMultimapCacheTest method testExplicitTx.

public void testExplicitTx() throws SystemException, NotSupportedException {
    initAndTest();
    MultimapCache<String, Person> multimapCache = getMultimapCacheMember(NAMES_KEY);
    TransactionManager tm1 = MultimapTestUtils.getTransactionManager(multimapCache);
    assertMultimapCacheSize(multimapCache, 1);
    tm1.begin();
    try {
        putValuesOnMultimapCache(multimapCache, NAMES_KEY, JULIEN);
        if (fromOwner) {
            assertContaisKeyValue(multimapCache, NAMES_KEY, JULIEN);
        }
        tm1.commit();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    assertValuesAndOwnership(NAMES_KEY, JULIEN);
    assertMultimapCacheSize(multimapCache, 2);
}
Also used : TransactionManager(javax.transaction.TransactionManager) Person(org.infinispan.test.data.Person) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 9 with Person

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

the class EagerKeyValueConverterTest method testWriteMap.

public void testWriteMap() throws InterruptedException {
    BlockingQueue<KeyValuePair<String, Person>> eventsQueue = new LinkedBlockingQueue<>();
    RemoteCache<String, Person> cache = remoteCacheManager.getCache();
    cache.addClientListener(new EventListener(eventsQueue, cache.getDataFormat()));
    Map<String, Person> data = new HashMap<>();
    data.put("1", new Person("John"));
    data.put("2", new Person("Mary"));
    data.put("3", new Person("George"));
    cache.putAll(data);
    KeyValuePair<String, Person> event = eventsQueue.poll(5, TimeUnit.SECONDS);
    assertNotNull(event);
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HashMap(java.util.HashMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Person(org.infinispan.test.data.Person)

Example 10 with Person

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

the class EventWithStorageTypeTest method testReceiveKeyValues.

@Test
public void testReceiveKeyValues() throws InterruptedException {
    RemoteCache<String, Person> cache = remoteCacheManager.getCache();
    EventListener listener = new EventListener();
    cache.addClientListener(listener);
    cache.put("1", new Person("John"));
    Object key = listener.getEventKey();
    assertNotNull(key);
    assertEquals("1", key);
}
Also used : Person(org.infinispan.test.data.Person) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Aggregations

Person (org.infinispan.test.data.Person)42 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)10 Test (org.testng.annotations.Test)10 Address (org.infinispan.test.data.Address)9 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)8 Marshaller (org.infinispan.commons.marshall.Marshaller)5 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)5 TransactionManager (javax.transaction.TransactionManager)4 Cache (org.infinispan.Cache)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 FunctionalTestUtils.await (org.infinispan.functional.FunctionalTestUtils.await)4 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)4 BeforeClass (org.testng.annotations.BeforeClass)4 Properties (java.util.Properties)3 AdvancedCache (org.infinispan.AdvancedCache)3 GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)3 DelegatingUserMarshaller (org.infinispan.marshall.core.impl.DelegatingUserMarshaller)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2