Search in sources :

Example 1 with SortedBeanKey

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

the class PrefixFieldSetComparatorTests method testStart.

@Test
public void testStart() {
    SortedBeanKey startOfRangeKey = new SortedBeanKey("a", "c", 2, null);
    SortedBeanKey candidateKey = new SortedBeanKey("a", "c", 2, "d");
    Assert.assertTrue(FieldSetRangeFilter.isCandidateAfterStartOfRange(candidateKey.getFields(), startOfRangeKey.getFields(), true, NODE_NAME));
    Assert.assertFalse(FieldSetRangeFilter.isCandidateAfterStartOfRange(candidateKey.getFields(), startOfRangeKey.getFields(), false, NODE_NAME));
}
Also used : SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Test(org.testng.annotations.Test)

Example 2 with SortedBeanKey

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

the class PrefixFieldSetComparatorTests method testInclusiveExclusive.

@Test
public void testInclusiveExclusive() {
    SortedBeanKey endOfRange2 = new SortedBeanKey("emu", "d", 5, "g");
    Range<SortedBeanKey> rangeEnd2Inclusive = new Range<>(null, true, endOfRange2, true);
    Range<SortedBeanKey> rangeEnd2Exclusive = new Range<>(null, true, endOfRange2, false);
    // the candidate would normally compare after the endOfRange, but should be included here
    SortedBeanKey candidate3 = new SortedBeanKey("emu", "d", 5, "g");
    Assert.assertTrue(candidate3.compareTo(endOfRange2) == 0);
    // but in the prefix range
    Assert.assertTrue(FieldSetRangeFilter.include(candidate3, rangeEnd2Inclusive, NODE_NAME));
    // even with inclusive=false
    Assert.assertFalse(FieldSetRangeFilter.include(candidate3, rangeEnd2Exclusive, NODE_NAME));
}
Also used : SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Range(io.datarouter.util.tuple.Range) Test(org.testng.annotations.Test)

Example 3 with SortedBeanKey

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

the class PrefixFieldSetComparatorTests method testEnd.

@Test
public void testEnd() {
    SortedBeanKey endOfRangeKey = new SortedBeanKey("a", "c", 2, null);
    SortedBeanKey candidateKey = new SortedBeanKey("a", "c", 2, "d");
    Assert.assertTrue(FieldSetRangeFilter.isCandidateBeforeEndOfRange(candidateKey.getFields(), endOfRangeKey.getFields(), true));
    Assert.assertFalse(FieldSetRangeFilter.isCandidateBeforeEndOfRange(candidateKey.getFields(), endOfRangeKey.getFields(), false));
}
Also used : SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Test(org.testng.annotations.Test)

Example 4 with SortedBeanKey

use of io.datarouter.storage.test.node.basic.sorted.SortedBeanKey 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 5 with SortedBeanKey

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

the class PrimaryKeyPercentCodecToolTests method testStringPkWithReservedCharacters.

@Test
public void testStringPkWithReservedCharacters() {
    String encoded = PrimaryKeyPercentCodecTool.encode(SBK_1);
    SortedBeanKey decoded = PrimaryKeyPercentCodecTool.decode(SortedBeanKey::new, encoded);
    Assert.assertEquals(decoded, SBK_1);
}
Also used : SortedBeanKey(io.datarouter.storage.test.node.basic.sorted.SortedBeanKey) Test(org.testng.annotations.Test)

Aggregations

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