Search in sources :

Example 6 with BinarySerializer

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"));
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) File(java.io.File) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) CompactFields(net.morimekta.test.providence.core.CompactFields) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UncheckedIOException(java.io.UncheckedIOException) SerializerException(net.morimekta.providence.serializer.SerializerException) Test(org.junit.Test)

Example 7 with BinarySerializer

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)));
}
Also used : Path(java.nio.file.Path) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) CompactFields(net.morimekta.test.providence.core.CompactFields) Test(org.junit.Test)

Example 8 with BinarySerializer

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))));
}
Also used : PrettySerializer(net.morimekta.providence.serializer.PrettySerializer) Containers(net.morimekta.test.providence.core.Containers) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Test(org.junit.Test)

Example 9 with BinarySerializer

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))));
    }
}
Also used : File(java.io.File) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Test(org.junit.Test)

Example 10 with BinarySerializer

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[] {}));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Test(org.junit.Test)

Aggregations

BinarySerializer (net.morimekta.providence.serializer.BinarySerializer)16 Test (org.junit.Test)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InetSocketAddress (java.net.InetSocketAddress)4 ExecutorService (java.util.concurrent.ExecutorService)4 Iface (net.morimekta.test.thrift.thrift.service.MyService.Iface)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 CompactFields (net.morimekta.test.providence.core.CompactFields)3 Duration (org.awaitility.Duration)3 File (java.io.File)2 ConnectException (java.net.ConnectException)2 Serializer (net.morimekta.providence.serializer.Serializer)2 MessageGenerator (net.morimekta.providence.util_internal.MessageGenerator)2 MyService (net.morimekta.test.providence.thrift.service.MyService)2 BeforeClass (org.junit.BeforeClass)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Path (java.nio.file.Path)1