@Test public void testPutAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); db.putAll(expected.iterator()); for (RevObject o : expected) { assertEquals(o, db.get(o.getId())); } }
@Test public void testPutAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); db.putAll(expected.iterator()); for (RevObject o : expected) { assertEquals(o, db.get(o.getId())); } }
@Test public void testGetAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } assertTrue(db.put(feature(5, "not queried 1"))); assertTrue(db.put(feature(6, "not queried 2"))); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterable<ObjectId> ids = Iterables.transform(expected, toId); Iterator<RevObject> iterator = db.getAll(ids); List<RevObject> actual = ImmutableList.copyOf(iterator); assertEquals(Sets.newHashSet(ids), Sets.newHashSet(Iterables.transform(actual, toId))); }
@Test public void testGetAll() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } assertTrue(db.put(feature(5, "not queried 1"))); assertTrue(db.put(feature(6, "not queried 2"))); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterable<ObjectId> ids = Iterables.transform(expected, toId); Iterator<RevObject> iterator = db.getAll(ids); List<RevObject> actual = ImmutableList.copyOf(iterator); assertEquals(Sets.newHashSet(ids), Sets.newHashSet(Iterables.transform(actual, toId))); }
@Test public void testGetIfPresent() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } for (RevObject o : expected) { assertEquals(o, db.getIfPresent(o.getId())); } assertNull(db.getIfPresent(RevObjectTestSupport.hashString("notfound"))); }
@Test public void testGetIfPresent() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } for (RevObject o : expected) { assertEquals(o, db.getIfPresent(o.getId())); } assertNull(db.getIfPresent(RevObjectTestSupport.hashString("notfound"))); }
@Test public void testDeleteAll() { ImmutableList<RevObject> objs = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null)); for (RevObject o : objs) { assertTrue(db.put(o)); } ObjectId notInDb1 = RevObjectTestSupport.hashString("fake1"); ObjectId notInDb2 = RevObjectTestSupport.hashString("fake2"); Function<RevObject, ObjectId> toId = p -> p.getId(); List<ObjectId> ids = Lists.newArrayList(concat(singletonIterator(notInDb1), transform(objs.iterator(), toId), singletonIterator(notInDb2))); db.deleteAll(ids.iterator()); for (ObjectId id : ids) { assertFalse(db.exists(id)); } }
@Test public void testDeleteAll() { ImmutableList<RevObject> objs = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null)); for (RevObject o : objs) { assertTrue(db.put(o)); } ObjectId notInDb1 = RevObjectTestSupport.hashString("fake1"); ObjectId notInDb2 = RevObjectTestSupport.hashString("fake2"); Function<RevObject, ObjectId> toId = p -> p.getId(); List<ObjectId> ids = Lists.newArrayList(concat(singletonIterator(notInDb1), transform(objs.iterator(), toId), singletonIterator(notInDb2))); db.deleteAll(ids.iterator()); for (ObjectId id : ids) { assertFalse(db.exists(id)); } }
@Test public void testGetAllWithListener() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } assertTrue(db.put(feature(5, "not queried 1"))); assertTrue(db.put(feature(6, "not queried 2"))); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterable<ObjectId> ids = Iterables.transform(expected, toId); CountingListener listener = BulkOpListener.newCountingListener(); Iterable<ObjectId> notFound = ImmutableList.of(RevObjectTestSupport.hashString("notfound1"), RevObjectTestSupport.hashString("notfound2")); Iterator<RevObject> result = db.getAll(Iterables.concat(notFound, ids), listener); List<RevObject> actual = ImmutableList.copyOf(result); assertEquals(Sets.newHashSet(ids), Sets.newHashSet(Iterables.transform(actual, toId))); assertEquals(expected.size(), listener.found()); assertEquals(2, listener.notFound()); }
@Test public void testGetAllWithListener() { ImmutableList<RevObject> expected = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null), RevTree.EMPTY); for (RevObject o : expected) { assertTrue(db.put(o)); } assertTrue(db.put(feature(5, "not queried 1"))); assertTrue(db.put(feature(6, "not queried 2"))); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterable<ObjectId> ids = Iterables.transform(expected, toId); CountingListener listener = BulkOpListener.newCountingListener(); Iterable<ObjectId> notFound = ImmutableList.of(RevObjectTestSupport.hashString("notfound1"), RevObjectTestSupport.hashString("notfound2")); Iterator<RevObject> result = db.getAll(Iterables.concat(notFound, ids), listener); List<RevObject> actual = ImmutableList.copyOf(result); assertEquals(Sets.newHashSet(ids), Sets.newHashSet(Iterables.transform(actual, toId))); assertEquals(expected.size(), listener.found()); assertEquals(2, listener.notFound()); }
@Test public void testDeleteAllWithListener() { ImmutableList<RevObject> objs = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null)); for (RevObject o : objs) { assertTrue(db.put(o)); } ObjectId notInDb1 = RevObjectTestSupport.hashString("fake1"); ObjectId notInDb2 = RevObjectTestSupport.hashString("fake2"); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterator<ObjectId> ids = concat(singletonIterator(notInDb1), transform(objs.iterator(), toId), singletonIterator(notInDb2)); CountingListener listener = BulkOpListener.newCountingListener(); db.deleteAll(ids, listener); assertEquals(3, listener.deleted()); assertEquals(2, listener.notFound()); }
/** * This tests the concurrency within the PGObjectStore by attempting to add the same object many * times with a small batch size. This causes the same object to be added by multiple threads * and should bring to light any concurrency issues with putting duplicate objects. */ @Test public void testPutAllConcurrency() { RevObject object = RevObjectTestSupport.feature(0, null, "some value"); List<RevObject> objects = new LinkedList<RevObject>(); for (int i = 0; i < 100; i++) { objects.add(object); } ((PGObjectStore) db).setPutAllBatchSize(1); db.putAll(objects.iterator()); assertEquals(object, db.get(object.getId())); }
@Test public void testDeleteAllWithListener() { ImmutableList<RevObject> objs = ImmutableList.of(feature(0, null, "some value"), feature(1, "value", new Integer(111)), feature(2, (Object) null)); for (RevObject o : objs) { assertTrue(db.put(o)); } ObjectId notInDb1 = RevObjectTestSupport.hashString("fake1"); ObjectId notInDb2 = RevObjectTestSupport.hashString("fake2"); Function<RevObject, ObjectId> toId = p -> p.getId(); Iterator<ObjectId> ids = concat(singletonIterator(notInDb1), transform(objs.iterator(), toId), singletonIterator(notInDb2)); CountingListener listener = BulkOpListener.newCountingListener(); db.deleteAll(ids, listener); assertEquals(3, listener.deleted()); assertEquals(2, listener.notFound()); }
@Test public void testGet() { RevFeature o = feature(0, null, "some value"); try { db.get(o.getId()); fail("expected IAE on non existent object"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("does not exist")); } assertTrue(db.put(o)); RevObject read = db.get(o.getId()); assertNotNull(read); assertEquals(o, read); }
@Test public void testGet() { RevFeature o = feature(0, null, "some value"); try { db.get(o.getId()); fail("expected IAE on non existent object"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("does not exist")); } assertTrue(db.put(o)); RevObject read = db.get(o.getId()); assertNotNull(read); assertEquals(o, read); }
@Test public void testGetWithCast() { RevFeature o = feature(0, null, "some value"); try { db.get(o.getId(), RevFeature.class); fail("expected IAE on non existent object"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("does not exist")); } assertTrue(db.put(o)); RevObject read = db.get(o.getId(), RevFeature.class); assertNotNull(read); assertEquals(o, read); try { db.get(o.getId(), RevTree.class); fail("expected IAE on wrong type expectation"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("does not exist")); } }
@Test public void testBuild() throws Exception { ObjectId meta1 = getOID(1); SimpleFeatureType fType1 = DataUtilities.createType("location", "the_geom:Point:srid=4326,name:String,name2:String"); RevFeatureType revft1 = RevFeatureTypeBuilder.create(getOID(1), fType1); ObjectDatabase odb = mock(ObjectDatabase.class); when(odb.getFeatureType(meta1)).thenReturn(revft1); WKTReader2 wkt = new WKTReader2(); RevFeature feat = RevObjectTestSupport.feature(wkt.read("POINT(0 0)"), "abc", "def"); Node n1 = Node.create("name1", getOID(2), meta1, TYPE.FEATURE, new Envelope()); NodeRef nr1 = new NodeRef(n1, "testcase", meta1); ObjectInfo<RevFeature> fi = ObjectInfo.of(nr1, feat); MultiFeatureTypeBuilder builder = new MultiFeatureTypeBuilder(odb); SimpleFeature sf = builder.apply(fi); Assert.isTrue(sf.getAttribute("name").equals("abc")); Assert.isTrue(sf.getAttribute("name2").equals("def")); }
@Test public void testBuild() throws Exception { ObjectId meta1 = getOID(1); SimpleFeatureType fType1 = DataUtilities.createType("location", "the_geom:Point:srid=4326,name:String,name2:String"); RevFeatureType revft1 = RevFeatureType.builder().id(getOID(1)).type(fType1).build(); ObjectDatabase odb = mock(ObjectDatabase.class); when(odb.getFeatureType(meta1)).thenReturn(revft1); WKTReader2 wkt = new WKTReader2(); RevFeature feat = RevObjectTestSupport.feature(wkt.read("POINT(0 0)"), "abc", "def"); Node n1 = RevObjectFactory.defaultInstance().createNode("name1", getOID(2), meta1, TYPE.FEATURE, new Envelope(), null); NodeRef nr1 = new NodeRef(n1, "testcase", meta1); ObjectInfo<RevFeature> fi = ObjectInfo.of(nr1, feat); MultiFeatureTypeBuilder builder = new MultiFeatureTypeBuilder(odb); SimpleFeature sf = builder.apply(fi); Assert.isTrue(sf.getAttribute("name").equals("abc")); Assert.isTrue(sf.getAttribute("name2").equals("def")); }
@Test public void testExists() { RevFeature o = feature(0, null, "some value"); assertFalse(db.exists(o.getId())); assertTrue(db.put(o)); assertTrue(db.exists(o.getId())); assertTrue(db.exists(o.getId())); }
@Test public void testExists() { RevFeature o = feature(0, null, "some value"); assertFalse(db.exists(o.getId())); assertTrue(db.put(o)); assertTrue(db.exists(o.getId())); assertTrue(db.exists(o.getId())); }