static int notifyInserted(Map<EncodedObject, Boolean> insertResults, BulkOpListener listener) { int newObjects = 0; for (Entry<EncodedObject, Boolean> entry : insertResults.entrySet()) { EncodedObject object = entry.getKey(); ObjectId id = object.id(); boolean inserted = entry.getValue().booleanValue(); if (inserted) { listener.inserted(id, null); newObjects++; } else { listener.found(id, null); } } return newObjects; }
@Test public void testCompositeListenerWithNoOp() { CountingListener countingListener = BulkOpListener.newCountingListener(); BulkOpListener listener = BulkOpListener.composite(countingListener, BulkOpListener.NOOP_LISTENER); assertEquals(countingListener, listener); listener = BulkOpListener.composite(BulkOpListener.NOOP_LISTENER, countingListener); assertEquals(countingListener, listener); listener = BulkOpListener.composite(BulkOpListener.NOOP_LISTENER, BulkOpListener.NOOP_LISTENER); assertEquals(BulkOpListener.NOOP_LISTENER, listener); listener.found(ObjectId.NULL, 0); listener.deleted(ObjectId.NULL); listener.inserted(ObjectId.NULL, 0); listener.notFound(ObjectId.NULL); }
private void testGetFeatures(final Iterable<Node> nodes, final int expectedSize) { CountingListener listener = BulkOpListener.newCountingListener(); Stopwatch sw = Stopwatch.createStarted(); Iterator<NodeRef> refs = Iterators.transform(nodes.iterator(), (n) -> NodeRef.create("layer", n)); Iterator<ObjectInfo<RevFeature>> iterator = db.getObjects(refs, listener, RevFeature.class); final int returnedObjectCount = Iterators.size(iterator); sw.stop(); System.err.printf("----- %,d Features queried (%,d not found) with getObjects() in %,dms\n", listener.found(), listener.notFound(), sw.elapsed(TimeUnit.MILLISECONDS)); System.err.printf("----- %s\n", sharedCache); Assert.assertEquals(listener.toString(), expectedSize, listener.found()); assertEquals(expectedSize, returnedObjectCount); }
@Override public void notFound(ObjectId id) { target.notFound(id); } }
/** * @return the number of objects parsed from the input stream */ public IngestResults ingest(final InputStream in, final Callback callback) { Iterator<RevObject> objects = streamToObjects(in); BulkOpListener listener = new BulkOpListener() { @Override public void inserted(final ObjectId objectId, @Nullable Integer storageSizeBytes) { callback.callback(new Supplier<RevObject>() { @Override public RevObject get() { return database.get(objectId); } }); } }; CountingListener countingListener = BulkOpListener.newCountingListener(); listener = BulkOpListener.composite(countingListener, listener); database.putAll(objects, listener); return new IngestResults(countingListener.inserted(), countingListener.found()); }
@Test public void testCompositeListener() { CountingListener countingListener1 = BulkOpListener.newCountingListener(); CountingListener countingListener2 = BulkOpListener.newCountingListener(); BulkOpListener listener = BulkOpListener.composite(countingListener1, countingListener2); assertEquals(0, countingListener2.notFound()); listener.found(ObjectId.NULL, 0); listener.found(ObjectId.NULL, 0); listener.deleted(ObjectId.NULL); listener.deleted(ObjectId.NULL); listener.deleted(ObjectId.NULL); listener.inserted(ObjectId.NULL, 0); listener.inserted(ObjectId.NULL, 0); listener.inserted(ObjectId.NULL, 0); listener.inserted(ObjectId.NULL, 0); listener.notFound(ObjectId.NULL); listener.notFound(ObjectId.NULL); listener.notFound(ObjectId.NULL); listener.notFound(ObjectId.NULL); listener.notFound(ObjectId.NULL);
private void testGetAll(final Iterable<ObjectId> ids, final int expectedSize) { CountingListener getAllListener = BulkOpListener.newCountingListener(); Stopwatch sw = Stopwatch.createStarted(); final int returnedObjectCount = Iterators .size(db.getAll(ids, getAllListener, RevFeature.class)); sw.stop(); System.err.printf( "----- %,d random objects queried (%,d not found) with getAll() in %,dms\n", getAllListener.found(), getAllListener.notFound(), sw.elapsed(TimeUnit.MILLISECONDS)); System.err.printf("----- %s\n", sharedCache); Assert.assertEquals(getAllListener.toString(), expectedSize, getAllListener.found()); assertEquals(expectedSize, returnedObjectCount); }
static int notifyInserted(Map<EncodedObject, Boolean> insertResults, BulkOpListener listener) { int newObjects = 0; for (Entry<EncodedObject, Boolean> entry : insertResults.entrySet()) { EncodedObject object = entry.getKey(); ObjectId id = object.id(); boolean inserted = entry.getValue().booleanValue(); if (inserted) { listener.inserted(id, null); newObjects++; } else { listener.found(id, null); } } return newObjects; }
@Override public void found(ObjectId object, @Nullable Integer storageSizeBytes) { target.found(object, storageSizeBytes); }