public void put(RevObject obj) { SharedCache cache = sharedCache.get(); CacheKey key = keyPrefix.create(obj.getId()); cache.put(key, obj); }
private Optional<ObjectId> verifyId(ObjectId objectId, RevObject.TYPE type) { final RevObject revObject = source.getIfPresent(objectId); checkArgument(revObject != null, "No object named %s could be found", objectId); if (type.equals(revObject.getType())) { return Optional.of(revObject.getId()); } else { throw new IllegalArgumentException(String.format("%s did not resolve to %s: %s", objectId, type, revObject.getType())); } }
@Override public void funnel(RevObject object) throws IOException { OutputStream out = getCurrentTarget(); out.write(object.getId().getRawValue()); serializer.write(object, out); out.flush(); }
private Optional<ObjectId> verifyId(ObjectId objectId, RevObject.TYPE type) { final RevObject revObject = source.getIfPresent(objectId); checkArgument(revObject != null, "No object named %s could be found", objectId); if (type.equals(revObject.getType())) { return Optional.of(revObject.getId()); } else { throw new IllegalArgumentException(String.format("%s did not resolve to %s: %s", objectId, type, revObject.getType())); } }
private EncodedObject encode(RevObject o) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer().write(o, out); } catch (IOException e) { throw new RuntimeException(e); } return new EncodedObject(o.getId(), o.getType(), out.toByteArray()); }
private EncodedObject encode(RevObject o) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer().write(o, out); } catch (IOException e) { throw Throwables.propagate(e); } return new EncodedObject(o.getId(), o.getType(), out.toByteArray()); }
public @Override boolean put(final RevObject object) { checkNotNull(object, "argument object is null"); checkArgument(!object.getId().isNull(), "ObjectId is NULL"); checkState(isOpen(), "db is closed"); ObjectId id = object.getId(); RevObject existing = objects.putIfAbsent(id, object); return null == existing; }
public @Override boolean put(final RevObject object) { checkNotNull(object, "argument object is null"); checkArgument(!object.getId().isNull(), "ObjectId is NULL"); checkState(isOpen(), "db is closed"); ObjectId id = object.getId(); RevObject existing = objects.putIfAbsent(id, object); return null == existing; }
private void copyObject(final ObjectId objectId, final ObjectStore from, final ObjectStore to) { RevObject object = from.get(objectId); if (object instanceof RevTree) { Set<ObjectId> metadataIds = new HashSet<ObjectId>(); copyTree(object.getId(), from, to, metadataIds); for (ObjectId metadataId : metadataIds) { copyObject(metadataId, from, to); } } else { copyObject(object, from, to); } }
public @Test void testInvalidateAll() { final int L1Capacity = 10; SharedCache cache = SharedCache.build(L1Capacity, 16 * 1024 * 1024); List<RevObject> objects = createObjects(500); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> cache.put(repo2Id.create(o.getId()), o)); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo2Id.create(o.getId())))); cache.invalidateAll(); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
private void testHashCommitsConsistency(RevObject o) throws Exception { ObjectId expected = o.getId(); ObjectId actual = hashCommand.setObject(o).call(); assertEquals(expected, actual); } }
public @Before void before() { mockSharedCache = mock(SharedCache.class); cacheId1 = new CacheIdentifier(0); cacheId2 = new CacheIdentifier(1000); cache1 = new ObjectCache(() -> mockSharedCache, cacheId1); cache2 = new ObjectCache(() -> mockSharedCache, cacheId2); o1 = RevFeature.builder().addValue(0L).addValue("zero").build(); o2 = RevFeature.builder().addValue(1L).addValue("one").build(); k11 = cacheId1.create(o1.getId()); k21 = cacheId2.create(o1.getId()); k22 = cacheId2.create(o2.getId()); }
@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"))); }
public @Test void testMultipleInstances() throws IOException { try (ObjectStore db2 = createOpen(false)) { assertNotSame(db, db2); RevObject obj = RevTree.EMPTY; assertTrue(db.put(obj)); assertFalse(db2.put(obj)); RevObject revObject = db2.get(obj.getId()); assertEquals(obj, revObject); } }
public @Test void testMultipleInstances() throws IOException { try (ObjectStore db2 = createOpen(false)) { assertNotSame(db, db2); RevObject obj = RevTree.EMPTY; assertTrue(db.put(obj)); assertFalse(db2.put(obj)); RevObject revObject = db2.get(obj.getId()); assertEquals(obj, revObject); } }