@Test public void testIndex() throws QueryException { Indexes is = new Indexes(); Index dIndex = is.addOrGetIndex("d", false); Index boolIndex = is.addOrGetIndex("bool", false); Index strIndex = is.addOrGetIndex("str", false); for (int i = 0; i < 1000; i++) { Data key = ss.toData(i); Data value = ss.toData(new MainPortable(i % 2 == 0, -10.34d, "joe" + i)); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); } assertEquals(1000, dIndex.getRecords(-10.34d).size()); assertEquals(1, strIndex.getRecords("joe23").size()); assertEquals(500, boolIndex.getRecords(true).size()); for (int i = 0; i < 1000; i++) { Data key = ss.toData(i); Data value = ss.toData(new MainPortable(false, 11.34d, "joe")); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); } assertEquals(0, dIndex.getRecords(-10.34d).size()); assertEquals(0, strIndex.getRecords("joe23").size()); assertEquals(1000, strIndex.getRecords("joe").size()); assertEquals(1000, boolIndex.getRecords(false).size()); assertEquals(0, boolIndex.getRecords(true).size()); for (int i = 0; i < 1000; i++) { Data key = ss.toData(i); Data value = ss.toData(new MainPortable(false, -1 * (i + 1), "joe" + i)); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); } assertEquals(0, dIndex.getSubRecordsBetween(1d, 1001d).size()); assertEquals(1000, dIndex.getSubRecordsBetween(-1d, -1001d).size()); for (int i = 0; i < 1000; i++) { Data key = ss.toData(i); Data value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i)); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); } assertEquals(1000, dIndex.getSubRecordsBetween(1d, 1001d).size()); assertEquals(0, dIndex.getSubRecordsBetween(-1d, -1001d).size()); assertEquals(400, dIndex.getSubRecords(ComparisonType.GREATER, 600d).size()); assertEquals(401, dIndex.getSubRecords(ComparisonType.GREATER_EQUAL, 600d).size()); assertEquals(9, dIndex.getSubRecords(ComparisonType.LESSER, 10d).size()); assertEquals(10, dIndex.getSubRecords(ComparisonType.LESSER_EQUAL, 10d).size()); assertEquals( 1, is.query(new AndPredicate(new EqualPredicate("d", 1d), new EqualPredicate("bool", "false"))) .size()); assertEquals( 1, is.query( new AndPredicate( new EqualPredicate("d", 1), new EqualPredicate("bool", Boolean.FALSE))) .size()); assertEquals( 1, is.query(new AndPredicate(new EqualPredicate("d", "1"), new EqualPredicate("bool", false))) .size()); }
@Test public void testRemoveEnumIndex() { Indexes is = new Indexes(); is.addOrGetIndex("favoriteCity", false); Data key = ss.toData(1); Data value = ss.toData(new SerializableWithEnum(SerializableWithEnum.City.Istanbul)); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); assertNotNull(is.getIndex("favoriteCity")); is.removeEntryIndex(key); assertEquals( 0, is.getIndex("favoriteCity").getRecords(SerializableWithEnum.City.Istanbul).size()); }
@Test public void testIndexWithNull() throws QueryException { Indexes is = new Indexes(); Index strIndex = is.addOrGetIndex("str", true); Data value = ss.toData(new MainPortable(false, 1, null)); Data key1 = ss.toData(0); is.saveEntryIndex(new QueryEntry(ss, key1, key1, value)); value = ss.toData(new MainPortable(false, 2, null)); Data key2 = ss.toData(1); is.saveEntryIndex(new QueryEntry(ss, key2, key2, value)); for (int i = 2; i < 1000; i++) { Data key = ss.toData(i); value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i)); is.saveEntryIndex(new QueryEntry(ss, key, key, value)); } Comparable c = null; assertEquals(2, strIndex.getRecords(c).size()); assertEquals(998, strIndex.getSubRecords(ComparisonType.NOT_EQUAL, null).size()); }