use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class MessageStreamsTest method testToFile.
@Test
public void testToFile() throws IOException {
File file = tmp.newFile();
int size = list.stream().collect(MessageCollectors.toFile(file, new BinarySerializer()));
assertThat(Files.size(file.toPath()), is((long) size));
List<CompactFields> out = MessageStreams.file(file, new BinarySerializer(), CompactFields.kDescriptor).collect(Collectors.toList());
assertThat(out, is(equalTo(list)));
try {
list.stream().collect(MessageCollectors.toFile(new File(tmp.getRoot(), "does/not"), new BinarySerializer()));
fail("no exception");
} catch (Exception e) {
assertThat(e, is(instanceOf(UncheckedIOException.class)));
assertThat(e.getMessage(), is("Unable to open not"));
}
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class MessageStreamsTest method testToPath.
@Test
public void testToPath() throws IOException {
Path file = tmp.newFile().toPath();
int size = list.stream().collect(MessageCollectors.toPath(file, new BinarySerializer()));
assertThat(Files.size(file), is((long) size));
List<CompactFields> out = MessageStreams.path(file, new BinarySerializer(), CompactFields.kDescriptor).collect(Collectors.toList());
assertThat(out, is(equalTo(list)));
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class LogformatterTest method testFormat_EverythingDefault.
@Test
public void testFormat_EverythingDefault() throws IOException {
Containers containers = MessageStreams.resource("/compat/binary.data", new BinarySerializer(), Containers.kDescriptor).findFirst().orElseThrow(() -> new AssertionError("resource"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new PrettySerializer().config().serialize(baos, containers);
assertThat(new LogFormatter(true).format(containers), is(equalToLines(new String(baos.toByteArray(), UTF_8))));
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class FileMessageRWTest method testBinary.
@Test
public void testBinary() throws IOException {
File test = tmp.newFile();
try (FileMessageWriter writer = new FileMessageWriter(test, new BinarySerializer())) {
writer.write(m1);
writer.separator();
writer.write(m2);
}
try (FileMessageReader reader = new FileMessageReader(test, new BinarySerializer())) {
assertThat(m1, is(equalTo(reader.read(CompactFields.kDescriptor))));
assertThat(m2, is(equalTo(reader.read(OptionalFields.kDescriptor))));
}
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class QueuedFileMessageWriterTest method testClose_closed.
@Test
public void testClose_closed() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
ExecutorService executor = mock(ExecutorService.class);
when(executor.isShutdown()).thenReturn(true);
QueuedMessageWriter writer = new QueuedMessageWriter(target, executor);
writer.close();
verify(executor).submit(any(Runnable.class));
verify(executor).isShutdown();
verifyNoMoreInteractions(executor);
assertThat(baos.toByteArray(), is(new byte[] {}));
}
Aggregations