Search in sources :

Example 1 with SortedBean

use of io.datarouter.storage.test.node.basic.sorted.SortedBean in project datarouter by hotpads.

the class JsonDatabeanToolTests method testMultiRoundTrip.

@Test
public void testMultiRoundTrip() {
    SortedBeanKey key0 = new SortedBeanKey("a", "b", 0, "d");
    SortedBeanKey key1 = new SortedBeanKey("a", "b", 1, "dasdf");
    SortedBeanKey key2 = new SortedBeanKey("a", "basdf", 2, "sdsdsd");
    List<SortedBeanKey> keysIn = List.of(key0, key1, key2);
    JsonArray jsonKeys = JsonDatabeanTool.primaryKeysToJson(keysIn, sortedBeanFielder.getKeyFielder());
    List<SortedBeanKey> keysOut = JsonDatabeanTool.primaryKeysFromJson(SortedBeanKey.class, sortedBeanFielder.getKeyFielder(), jsonKeys);
    Assert.assertEquals(keysOut.size(), 3);
    Assert.assertEquals(keysOut.toArray(), keysIn.toArray());
    SortedBean bean0 = new SortedBean(key0, "1", 2L, null, 45.67d);
    SortedBean bean1 = new SortedBean(key1, "ert", -987654L, "cheesetoast", -45.67d);
    List<SortedBean> databeansIn = List.of(bean0, bean1);
    JsonArray jsonDatabeans = JsonDatabeanTool.databeansToJson(databeansIn, sortedBeanFielder);
    List<SortedBean> databeansOut = JsonDatabeanTool.databeansFromJson(ReflectionTool.supplier(SortedBean.class), sortedBeanFielder, jsonDatabeans);
    Assert.assertEquals(databeansOut.size(), 2);
    Assert.assertEquals(databeansOut.toArray(), databeansIn.toArray());
    Assert.assertEquals(Scanner.of(databeansOut).map(Databean::getKey).list(), keysIn.subList(0, 2));
}
Also used : JsonArray(com.google.gson.JsonArray) SortedBean(io.datarouter.storage.test.node.basic.sorted.SortedBean) SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Databean(io.datarouter.model.databean.Databean) Test(org.testng.annotations.Test)

Example 2 with SortedBean

use of io.datarouter.storage.test.node.basic.sorted.SortedBean in project datarouter by hotpads.

the class HBaseSortedNodeIntegrationTests method testEmptyTrailingStringInKey.

@Test
public void testEmptyTrailingStringInKey() {
    String firstField = "testEmptyTrailingStringInKey";
    String trailingString = "";
    SortedBeanKey pk = new SortedBeanKey(firstField, "bar", 3, trailingString);
    SortedBean input = new SortedBean(pk, "f1", 2L, "f3", 4D);
    dao.put(input);
    SortedBean getOutput = dao.get(pk);
    Assert.assertEquals(getOutput, input);
    dao.delete(pk);
}
Also used : SortedBean(io.datarouter.storage.test.node.basic.sorted.SortedBean) SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Test(org.testng.annotations.Test)

Aggregations

SortedBean (io.datarouter.storage.test.node.basic.sorted.SortedBean)2 SortedBeanKey (io.datarouter.storage.test.node.basic.sorted.SortedBeanKey)2 Test (org.testng.annotations.Test)2 JsonArray (com.google.gson.JsonArray)1 Databean (io.datarouter.model.databean.Databean)1