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);
}
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"));
}
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());
}
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());
}
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();
}
Aggregations