|
|
@@ -6,20 +6,27 @@ import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import net.ranides.assira.collection.lists.VirtualList;
|
|
|
+import net.ranides.assira.collection.maps.ArrayMap;
|
|
|
+import net.ranides.assira.collection.maps.MapBuilder;
|
|
|
import net.ranides.assira.collection.query.base.CQArray;
|
|
|
import net.ranides.assira.collection.query.base.CQArraySupplier;
|
|
|
import net.ranides.assira.collection.query.base.CQIterator;
|
|
|
import net.ranides.assira.collection.query.base.CQListSupplier;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
public class CQueryAbstractTest {
|
|
|
|
|
|
@Test
|
|
|
- public void validateContent() {
|
|
|
+ public void testContent() {
|
|
|
Integer[] array = {3, 4, 5, 6};
|
|
|
List<Integer> expected = new ArrayList<>(Arrays.asList(array));
|
|
|
|
|
|
@@ -34,7 +41,7 @@ public class CQueryAbstractTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void validateContentForSpecialFeatures() {
|
|
|
+ public void testContentForSpecialFeatures() {
|
|
|
Integer[] array = {3, 4, 5, 6};
|
|
|
List<Integer> expected = new ArrayList<>(Arrays.asList(array));
|
|
|
|
|
|
@@ -52,7 +59,7 @@ public class CQueryAbstractTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void validateJoin() {
|
|
|
+ public void testJoin() {
|
|
|
Integer[] array = {3, 4, 5, 6};
|
|
|
List<Integer> expected = new ArrayList<>(Arrays.asList(array));
|
|
|
|
|
|
@@ -70,7 +77,7 @@ public class CQueryAbstractTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void validateFetch() {
|
|
|
+ public void testFetch() {
|
|
|
AtomicInteger counter = new AtomicInteger(0);
|
|
|
AtomicInteger state = new AtomicInteger(777);
|
|
|
List<Integer> list = VirtualList.of(5, i -> {
|
|
|
@@ -116,7 +123,7 @@ public class CQueryAbstractTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void validatePrefetch() {
|
|
|
+ public void testPrefetch() {
|
|
|
AtomicInteger counter = new AtomicInteger(0);
|
|
|
AtomicInteger state = new AtomicInteger(777);
|
|
|
List<Integer> list = VirtualList.of(5, i -> {
|
|
|
@@ -160,8 +167,55 @@ public class CQueryAbstractTest {
|
|
|
Assert.assertEquals(base+10, counter.get());
|
|
|
}
|
|
|
|
|
|
-// @Test
|
|
|
-// public void validateList() {
|
|
|
+ @Test
|
|
|
+ public void testCache() throws IOException {
|
|
|
+ AtomicInteger counter = new AtomicInteger(0);
|
|
|
+ AtomicInteger state = new AtomicInteger(777);
|
|
|
+ List<Integer> list = VirtualList.of(5, i -> {
|
|
|
+ counter.incrementAndGet();
|
|
|
+ return state.get()+i;
|
|
|
+ });
|
|
|
+
|
|
|
+ Path file = File.createTempFile("cquery2", ".bin").toPath();
|
|
|
+ Files.deleteIfExists(file);
|
|
|
+
|
|
|
+ state.set(10);
|
|
|
+ CQuery<Integer> a = CQListSupplier.from(true, () -> list).cache(file);
|
|
|
+ Assert.assertEquals(5, counter.get());
|
|
|
+
|
|
|
+ state.set(20);
|
|
|
+ CQueryAssert.assertEquals(Arrays.asList(10,11,12,13,14), a);
|
|
|
+ Assert.assertEquals(5, counter.get());
|
|
|
+
|
|
|
+ state.set(30);
|
|
|
+ CQueryAssert.assertEquals(Arrays.asList(10,11,12,13,14), a);
|
|
|
+ Assert.assertEquals(5, counter.get());
|
|
|
+
|
|
|
+ CQuery<Integer> b = CQListSupplier.from(true, () -> list).cache(file);
|
|
|
+ CQuery<Integer> c = CQListSupplier.from(true, () -> list);
|
|
|
+
|
|
|
+ state.set(40);
|
|
|
+ CQueryAssert.assertEquals(Arrays.asList(10,11,12,13,14), b);
|
|
|
+ Assert.assertEquals(5, counter.get());
|
|
|
+ CQueryAssert.assertEquals(Arrays.asList(40,41,42,43,44), c);
|
|
|
+ Assert.assertTrue(counter.get() > 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGroup() {
|
|
|
+ Integer[] array = {4, 5, 6, 7, 8, 9};
|
|
|
+ List<Integer> expected = new ArrayList<>(Arrays.asList(array));
|
|
|
+
|
|
|
+ CQueryAssert.assertGroup(expected, CQueryMockup.of("each1", array));
|
|
|
+ CQueryAssert.assertGroup(expected, CQueryMockup.of("each2", array));
|
|
|
+ CQueryAssert.assertGroup(expected, CQueryMockup.of("stream", array));
|
|
|
+ CQueryAssert.assertGroup(expected, CQueryMockup.of("iterator", array));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // @Test
|
|
|
+// public void testList() {
|
|
|
// // TODO: in fact, we must not return VIEW of data, but independent list
|
|
|
// // Independent means:
|
|
|
// // - modification of source collection should not be visible
|