use of net.morimekta.test.providence.storage.Containers in project providence by morimekta.
the class DirectoryMessageStoreTest method testDirectoryStore.
@Test
public void testDirectoryStore() throws IOException, InterruptedException {
Map<UUID, Containers> source = new HashMap<>();
for (int i = 0; i < 100; ++i) {
source.put(UUID.randomUUID(), generator.generate(Containers.kDescriptor));
}
try (DirectoryMessageStore<UUID, Containers, Containers._Field> store = new DirectoryMessageStore<>(tmp.getRoot(), UUID::toString, UUID::fromString, Containers.kDescriptor, new PrettySerializer().config())) {
store.putAll(source);
} catch (IOException e) {
fail(e.getMessage());
}
Thread.sleep(1);
try (DirectoryMessageStore<UUID, Containers, Containers._Field> store = new DirectoryMessageStore<>(tmp.getRoot(), UUID::toString, UUID::fromString, Containers.kDescriptor, new PrettySerializer().config())) {
assertThat(store.keys(), is(source.keySet()));
Set<UUID> random5 = new HashSet<>();
source.forEach((k, v) -> {
if (random5.size() < 5) {
random5.add(k);
}
assertThat(store.containsKey(k), is(true));
assertThat(k.toString(), store.get(k), is(equalToMessage(v)));
});
for (int i = 0; i < 100; ++i) {
assertThat(store.containsKey(UUID.randomUUID()), is(false));
}
assertThat(store.getAll(source.keySet()), is(source));
store.removeAll(random5);
for (UUID k : random5) {
assertThat(store.containsKey(k), is(false));
assertThat(store.get(k), is(nullValue()));
}
} catch (IOException e) {
fail(e.getMessage());
}
}
use of net.morimekta.test.providence.storage.Containers in project providence by morimekta.
the class InMemoryMessageStoreTest method testStore.
@Test
public void testStore() {
MessageStore<UUID, Containers, Containers._Field> store = new InMemoryMessageStore<>();
for (int i = 0; i < 100; ++i) {
store.put(UUID.randomUUID(), generator.generate(Containers.kDescriptor));
}
TreeSet<UUID> ids = new TreeSet<>(store.keys());
assertThat(ids, hasSize(100));
for (UUID id : ids) {
assertThat(store.containsKey(id), is(true));
}
TreeSet<UUID> missing = new TreeSet<>();
for (int i = 0; i < 100; ++i) {
UUID uuid = UUID.randomUUID();
assertThat(store.containsKey(uuid), is(false));
;
missing.add(uuid);
}
assertThat(store.getAll(missing).entrySet(), hasSize(0));
store.remove(ids.first());
store.removeAll(new ArrayList<>(ids).subList(45, 55));
assertThat(store.getAll(ids).entrySet(), hasSize(89));
Map<UUID, Containers._Builder> bld = store.getAllBuilders(new ArrayList<>(ids).subList(30, 45));
bld.forEach((k, b) -> {
b.clearBinaryList();
b.clearBooleanList();
b.clearListListI32();
b.clearByteList();
});
store.putAllBuilders(bld);
Map<UUID, Containers> tmp2 = store.getAll(bld.keySet());
tmp2.forEach((k, v) -> {
assertThat(v.hasBinaryList(), is(false));
assertThat(v.hasBooleanList(), is(false));
assertThat(v.hasListListI32(), is(false));
assertThat(v.hasByteList(), is(false));
});
Containers._Builder builder = Containers.builder();
builder.addToIntegerList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
UUID uuid = UUID.randomUUID();
store.putBuilder(uuid, builder);
Containers containers = store.get(uuid);
assertThat(containers, is(notNullValue()));
assertThat(containers.getIntegerList(), is(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
Containers._Builder otherBuilder = store.getBuilder(uuid);
assertThat(containers, is(equalToMessage(otherBuilder.build())));
}
Aggregations