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();
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hadoop by apache.
the class TestDecommissioningStatus method checkDFSAdminDecommissionStatus.
private void checkDFSAdminDecommissionStatus(List<DatanodeDescriptor> expectedDecomm, DistributedFileSystem dfs, DFSAdmin admin) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream oldOut = System.out;
System.setOut(ps);
try {
// Parse DFSAdmin just to check the count
admin.report(new String[] { "-decommissioning" }, 0);
String[] lines = baos.toString().split("\n");
Integer num = null;
int count = 0;
for (String line : lines) {
if (line.startsWith("Decommissioning datanodes")) {
// Pull out the "(num)" and parse it into an int
String temp = line.split(" ")[2];
num = Integer.parseInt((String) temp.subSequence(1, temp.length() - 2));
}
if (line.contains("Decommission in progress")) {
count++;
}
}
assertTrue("No decommissioning output", num != null);
assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), num.intValue());
assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), count);
// Check Java API for correct contents
List<DatanodeInfo> decomming = new ArrayList<DatanodeInfo>(Arrays.asList(dfs.getDataNodeStats(DatanodeReportType.DECOMMISSIONING)));
assertEquals("Unexpected number of decomming DNs", expectedDecomm.size(), decomming.size());
for (DatanodeID id : expectedDecomm) {
assertTrue("Did not find expected decomming DN " + id, decomming.contains(id));
}
} finally {
System.setOut(oldOut);
}
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hadoop by apache.
the class TestHsJobBlock method testHsJobBlockForOversizeJobShouldDisplayWarningMessage.
@Test
public void testHsJobBlockForOversizeJobShouldDisplayWarningMessage() {
int maxAllowedTaskNum = 100;
Configuration config = new Configuration();
config.setInt(JHAdminConfig.MR_HS_LOADED_JOBS_TASKS_MAX, maxAllowedTaskNum);
JobHistory jobHistory = new JobHistoryStubWithAllOversizeJobs(maxAllowedTaskNum);
jobHistory.init(config);
HsJobBlock jobBlock = new HsJobBlock(jobHistory) {
// override this so that job block can fetch a job id.
@Override
public Map<String, String> moreParams() {
Map<String, String> map = new HashMap<>();
map.put(AMParams.JOB_ID, "job_0000_0001");
return map;
}
};
// set up the test block to render HsJobBLock to
OutputStream outputStream = new ByteArrayOutputStream();
HtmlBlock.Block block = createBlockToCreateTo(outputStream);
jobBlock.render(block);
block.getWriter().flush();
String out = outputStream.toString();
Assert.assertTrue("Should display warning message for jobs that have too " + "many tasks", out.contains("Any job larger than " + maxAllowedTaskNum + " will not be loaded"));
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hive by apache.
the class TestExplainTask method explainToString.
private <K, V> String explainToString(Map<K, V> explainMap) throws Exception {
ExplainWork work = new ExplainWork();
ParseContext pCtx = new ParseContext();
HashMap<String, TableScanOperator> topOps = new HashMap<>();
TableScanOperator scanOp = new DummyOperator(new DummyExplainDesc<K, V>(explainMap));
topOps.put("sample", scanOp);
pCtx.setTopOps(topOps);
work.setParseContext(pCtx);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
work.setConfig(new ExplainConfiguration());
new ExplainTask().getJSONLogicalPlan(new PrintStream(baos), work);
baos.close();
return baos.toString();
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hive by apache.
the class KryoSerializer method serialize.
public static byte[] serialize(Object object) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Output output = new Output(stream);
Kryo kryo = SerializationUtilities.borrowKryo();
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
try {
kryo.writeObject(output, object);
} finally {
SerializationUtilities.releaseKryo(kryo);
}
// close() also calls flush()
output.close();
return stream.toByteArray();
}
Aggregations