Search in sources :

Example 1 with Address

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

the class JavaSerializationTranscoderTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() {
    dataSrc = new Person("Joe");
    Address address = new Address();
    address.setCity("London");
    dataSrc.setAddress(address);
    transcoder = new JavaSerializationTranscoder(new ClassAllowList(Collections.singletonList(".*")));
    supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
Also used : Address(org.infinispan.test.data.Address) JavaSerializationTranscoder(org.infinispan.encoding.impl.JavaSerializationTranscoder) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) Person(org.infinispan.test.data.Person) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with Address

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

the class ProtostreamTranscoderTest method testToFromJson.

@Test
public void testToFromJson() throws IOException {
    String type = "org.infinispan.test.core.Address";
    String street = "Elm Street";
    String city = "NYC";
    int zip = 123;
    Address data = new Address(street, city, zip);
    String jsonString = Json.object().set("_type", type).set("street", street).set("city", city).set("zip", zip).toString();
    byte[] byteJson = jsonString.getBytes(UTF_8);
    // Converting from json strings to protostream with different binary encodings
    Object protoWithNoEncoding = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM);
    assertArrayEquals(toWrappedByteArray(ctx, data), (byte[]) protoWithNoEncoding);
    Object protoHex = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("hex"));
    assertEquals(protoHex, Base16Codec.encode((byte[]) protoWithNoEncoding));
    Object protoBase64 = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("base64"));
    assertEquals(protoBase64, Base64.getEncoder().encode((byte[]) protoWithNoEncoding));
    // Converting from json byte[] to protostream with different binary encodings
    protoWithNoEncoding = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM);
    assertArrayEquals(toWrappedByteArray(ctx, data), (byte[]) protoWithNoEncoding);
    protoHex = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("hex"));
    assertEquals(protoHex, Base16Codec.encode((byte[]) protoWithNoEncoding));
    protoBase64 = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("base64"));
    assertEquals(protoBase64, Base64.getEncoder().encode((byte[]) protoWithNoEncoding));
    // Converting from protostream to json with different output binary encoding
    Object result = transcoder.transcode(protoWithNoEncoding, APPLICATION_PROTOSTREAM, APPLICATION_JSON);
    assertTrue(result instanceof byte[]);
    assertJsonCorrect(result);
    result = transcoder.transcode(protoHex, APPLICATION_PROTOSTREAM.withEncoding("hex"), APPLICATION_JSON);
    assertTrue(result instanceof byte[]);
    assertJsonCorrect(result);
    result = transcoder.transcode(protoBase64, APPLICATION_PROTOSTREAM.withEncoding("base64"), APPLICATION_JSON);
    assertTrue(result instanceof byte[]);
    assertJsonCorrect(result);
    result = transcoder.transcode(protoHex, APPLICATION_PROTOSTREAM.withEncoding("hex"), APPLICATION_JSON.withClassType(String.class));
    assertTrue(result instanceof String);
    assertJsonCorrect(result);
}
Also used : Address(org.infinispan.test.data.Address) Test(org.testng.annotations.Test) AbstractTranscoderTest(org.infinispan.test.dataconversion.AbstractTranscoderTest)

Example 3 with Address

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

the class BaseStoreFunctionalTest method testPreloadStoredAsBinary.

public void testPreloadStoredAsBinary() {
    ConfigurationBuilder cb = getDefaultCacheConfiguration();
    createCacheStoreConfig(cb.persistence(), "testPreloadStoredAsBinary", true).memory().storageType(StorageType.BINARY);
    TestingUtil.defineConfiguration(cacheManager, "testPreloadStoredAsBinary", cb.build());
    Cache<String, Person> cache = cacheManager.getCache("testPreloadStoredAsBinary");
    cache.start();
    assert cache.getCacheConfiguration().persistence().preload();
    assertEquals(StorageType.BINARY, cache.getCacheConfiguration().memory().storageType());
    byte[] pictureBytes = new byte[] { 1, 82, 123, 19 };
    cache.put("k1", new Person("1"));
    cache.put("k2", new Person("2", null, pictureBytes, null, null, false), 111111, TimeUnit.MILLISECONDS);
    cache.put("k3", new Person("3", null, null, Sex.MALE, null, false), -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS);
    cache.put("k4", new Person("4", new Address("Street", "City", 12345), null, null, null, true), 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS);
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("EST"));
    calendar.set(2009, Calendar.MARCH, 18, 3, 22, 57);
    // Chop off the last milliseconds as some databases don't have that high of accuracy
    calendar.setTimeInMillis((calendar.getTimeInMillis() / 1000) * 1000);
    Date infinispanBirthDate = calendar.getTime();
    Person infinispanPerson = createEmptyPerson("Infinispan");
    infinispanPerson.setBirthDate(infinispanBirthDate);
    infinispanPerson.setAcceptedToS(true);
    cache.put("Infinispan", infinispanPerson);
    // Just to prove nothing in memory even with stop
    cache.getAdvancedCache().getDataContainer().clear();
    assertEquals(createEmptyPerson("1"), cache.get("k1"));
    Person person2 = createEmptyPerson("2");
    person2.setPicture(pictureBytes);
    assertEquals(person2, cache.get("k2"));
    Person person3 = createEmptyPerson("3");
    person3.setSex(Sex.MALE);
    assertEquals(person3, cache.get("k3"));
    assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
    assertEquals(infinispanPerson, cache.get("Infinispan"));
    cache.stop();
    cache.start();
    assertEquals(5, cache.entrySet().size());
    assertEquals(createEmptyPerson("1"), cache.get("k1"));
    assertEquals(person2, cache.get("k2"));
    assertEquals(person3, cache.get("k3"));
    assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
    assertEquals(infinispanPerson, cache.get("Infinispan"));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) Address(org.infinispan.test.data.Address) Calendar(java.util.Calendar) Person(org.infinispan.test.data.Person) Date(java.util.Date)

Example 4 with Address

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

the class QueriesJdbcJoinTest method samplePerson.

private Person samplePerson(String name) {
    Address address = new Address();
    address.setCity("London");
    address.setStreet("Cool Street");
    address.setZip(1321);
    return new Person(name, address, new byte[] { 0x1, 0x12 }, Sex.MALE, new java.util.Date(1629495308), true);
}
Also used : Address(org.infinispan.test.data.Address) Person(org.infinispan.test.data.Person)

Example 5 with Address

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

the class PersonKey2StringMapper method getStringMapping.

public String getStringMapping(Object key) {
    Person person = (Person) key;
    Address addr = person.getAddress();
    if (addr == null)
        return person.getName();
    return person.getName() + "_" + addr.getStreet() + "_" + addr.getCity() + "_" + addr.getZip();
}
Also used : Address(org.infinispan.test.data.Address) Person(org.infinispan.test.data.Person)

Aggregations

Address (org.infinispan.test.data.Address)10 Person (org.infinispan.test.data.Person)9 BeforeClass (org.testng.annotations.BeforeClass)4 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)2 PreparedStatement (java.sql.PreparedStatement)1 Timestamp (java.sql.Timestamp)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1 DefaultTranscoder (org.infinispan.commons.dataconversion.DefaultTranscoder)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 PersistenceConfigurationBuilder (org.infinispan.configuration.cache.PersistenceConfigurationBuilder)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 JavaSerializationTranscoder (org.infinispan.encoding.impl.JavaSerializationTranscoder)1 AbstractTranscoderTest (org.infinispan.test.dataconversion.AbstractTranscoderTest)1 Test (org.testng.annotations.Test)1