use of net.morimekta.providence.serializer.PrettySerializer in project providence by morimekta.
the class DirectoryMessageListStoreTest method testStore.
@Test
public void testStore() {
Map<UUID, List<OptionalFields>> source = new HashMap<>();
for (int i = 0; i < 100; ++i) {
UUID uuid = UUID.randomUUID();
for (int j = 0; j < 10; ++j) {
source.computeIfAbsent(uuid, u -> new ArrayList<>(10)).add(generator.generate(OptionalFields.kDescriptor));
}
}
try (DirectoryMessageListStore<UUID, OptionalFields, OptionalFields._Field> store = new DirectoryMessageListStore<>(tmp.getRoot(), UUID::toString, UUID::fromString, OptionalFields.kDescriptor, new PrettySerializer().config())) {
store.putAll(source);
} catch (IOException e) {
fail(e.getMessage());
}
try (DirectoryMessageListStore<UUID, OptionalFields, OptionalFields._Field> store = new DirectoryMessageListStore<>(tmp.getRoot(), UUID::toString, UUID::fromString, OptionalFields.kDescriptor, new PrettySerializer().config())) {
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, List<OptionalFields._Builder>> bld = store.getAllBuilders(new ArrayList<>(ids).subList(30, 45));
bld.forEach((k, list) -> {
for (OptionalFields._Builder b : list) {
b.clearBinaryValue();
b.clearBooleanValue();
b.clearByteValue();
}
});
store.putAllBuilders(bld);
Map<UUID, List<OptionalFields>> tmp2 = store.getAll(bld.keySet());
tmp2.forEach((k, list) -> {
for (OptionalFields v : list) {
assertThat(v.hasBooleanValue(), is(false));
assertThat(v.hasByteValue(), is(false));
assertThat(v.hasBinaryValue(), is(false));
}
});
OptionalFields._Builder builder = OptionalFields.builder();
builder.setIntegerValue(10);
builder.setBooleanValue(true);
builder.setDoubleValue(12345.6789);
UUID uuid = UUID.randomUUID();
store.putBuilders(uuid, ImmutableList.of(builder));
List<OptionalFields> list = store.get(uuid);
assertThat(list, hasSize(1));
assertThat(list, hasItem(builder.build()));
List<OptionalFields._Builder> otherBuilder = store.getBuilders(uuid);
assertThat(otherBuilder, hasSize(1));
assertThat(otherBuilder.get(0).build(), is(equalToMessage(builder.build())));
} catch (IOException e) {
fail(e.getMessage());
}
}
use of net.morimekta.providence.serializer.PrettySerializer 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());
}
}
Aggregations