Search in sources :

Example 11 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project Gaffer by gchq.

the class CompactRawLongSerialiserTest method test.

private static void test(final long value) throws SerialisationException {
    final byte[] b = SERIALISER.serialise(value);
    final Object o = SERIALISER.deserialise(b);
    assertEquals(Long.class, o.getClass());
    assertEquals(value, o);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CompactRawSerialisationUtils.write(value, new DataOutputStream(baos));
    final long result = CompactRawSerialisationUtils.read(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
    assertEquals(result, value);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 12 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project cassandra by apache.

the class MultiResultLoggerTest method printingExceptions.

@Test
public void printingExceptions() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(output, true);
    MultiResultLogger underTest = new MultiResultLogger(printStream);
    underTest.printException(new RuntimeException("Bad things"));
    String stackTrace = output.toString();
    assertTrue("Expected strack trace to be printed but got: " + stackTrace, stackTrace.startsWith("java.lang.RuntimeException: Bad things\n" + "\tat org.apache.cassandra.stress.util.MultiResultLoggerTest.printingExceptions"));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 13 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project cassandra by apache.

the class MultiResultLoggerTest method delegatesToInitialPrintStream.

@Test
public void delegatesToInitialPrintStream() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(output, true);
    MultiResultLogger underTest = new MultiResultLogger(printStream);
    underTest.println("Very important result");
    assertEquals("Very important result\n", output.toString());
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 14 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project cassandra by apache.

the class MultiResultLoggerTest method delegatesToAdditionalPrintStreams.

@Test
public void delegatesToAdditionalPrintStreams() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintStream additionalPrintStream = new PrintStream(output, true);
    MultiResultLogger underTest = new MultiResultLogger(new PrintStream(NOOP));
    underTest.addStream(additionalPrintStream);
    underTest.println("Very important result");
    assertEquals("Very important result\n", output.toString());
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 15 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project flink by apache.

the class StateBackendTestBase method testValueStateNullUpdate.

/**
	 * This test verifies that passing {@code null} to {@link ValueState#update(Object)} acts
	 * the same as {@link ValueState#clear()}.
	 *
	 * @throws Exception
	 */
@Test
@SuppressWarnings("unchecked")
public void testValueStateNullUpdate() throws Exception {
    // later if null values where actually stored in the state instead of acting as clear()
    try {
        LongSerializer.INSTANCE.serialize(null, new DataOutputViewStreamWrapper(new ByteArrayOutputStream()));
        fail("Should fail with NullPointerException");
    } catch (NullPointerException e) {
    // alrighty
    }
    CheckpointStreamFactory streamFactory = createStreamFactory();
    AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
    ValueStateDescriptor<Long> kvId = new ValueStateDescriptor<>("id", LongSerializer.INSTANCE, 42L);
    kvId.initializeSerializerUnlessSet(new ExecutionConfig());
    ValueState<Long> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
    // some modifications to the state
    backend.setCurrentKey(1);
    // verify default value
    assertEquals(42L, (long) state.value());
    state.update(1L);
    assertEquals(1L, (long) state.value());
    backend.setCurrentKey(2);
    assertEquals(42L, (long) state.value());
    backend.setCurrentKey(1);
    state.clear();
    assertEquals(42L, (long) state.value());
    state.update(17L);
    assertEquals(17L, (long) state.value());
    state.update(null);
    assertEquals(42L, (long) state.value());
    // draw a snapshot
    KeyGroupsStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forFullCheckpoint()));
    backend.dispose();
    backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot1);
    snapshot1.discardState();
    backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
    backend.dispose();
}
Also used : ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) BlockerCheckpointStreamFactory(org.apache.flink.runtime.util.BlockerCheckpointStreamFactory) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)92 Test (org.junit.Test)36 DataOutputStream (java.io.DataOutputStream)15 IOException (java.io.IOException)14 HashSet (java.util.HashSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)12 PrintStream (java.io.PrintStream)10 SparkConf (org.apache.spark.SparkConf)10 Edge (uk.gov.gchq.gaffer.data.element.Edge)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)10 Graph (uk.gov.gchq.gaffer.graph.Graph)10 User (uk.gov.gchq.gaffer.user.User)10 File (java.io.File)9 HashMap (java.util.HashMap)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)6