use of java.io.ByteArrayOutputStream in project hadoop by apache.
the class TestFindClass method testPrintLog4J.
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Test
public void testPrintLog4J() throws Throwable {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
FindClass.setOutputStreams(out, System.err);
run(FindClass.SUCCESS, FindClass.A_PRINTRESOURCE, LOG4J_PROPERTIES);
//here the content should be done
out.flush();
String body = baos.toString("UTF8");
LOG.info(LOG4J_PROPERTIES + " =\n" + body);
assertTrue(body.contains("Apache"));
}
use of java.io.ByteArrayOutputStream in project hadoop by apache.
the class TestProtoUtil method doVarIntTest.
private void doVarIntTest(int value) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CodedOutputStream cout = CodedOutputStream.newInstance(baos);
cout.writeRawVarint32(value);
cout.flush();
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
assertEquals(value, ProtoUtil.readRawVarint32(dis));
}
use of java.io.ByteArrayOutputStream in project hadoop by apache.
the class TestFsShellPermission method execCmd.
static String execCmd(FsShell shell, final String[] args) throws Exception {
ByteArrayOutputStream baout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baout, true);
PrintStream old = System.out;
int ret;
try {
System.setOut(out);
ret = shell.run(args);
out.close();
} finally {
System.setOut(old);
}
return String.valueOf(ret);
}
use of java.io.ByteArrayOutputStream in project hadoop by apache.
the class TestPacketReceiver method doTestReceiveAndMirror.
private void doTestReceiveAndMirror(PacketReceiver pr, int dataLen, int checksumsLen) throws IOException {
final byte[] DATA = AppendTestUtil.initBuffer(dataLen);
final byte[] CHECKSUMS = AppendTestUtil.initBuffer(checksumsLen);
byte[] packet = prepareFakePacket(DATA, CHECKSUMS);
ByteArrayInputStream in = new ByteArrayInputStream(packet);
pr.receiveNextPacket(in);
ByteBuffer parsedData = pr.getDataSlice();
assertArrayEquals(DATA, remainingAsArray(parsedData));
ByteBuffer parsedChecksums = pr.getChecksumSlice();
assertArrayEquals(CHECKSUMS, remainingAsArray(parsedChecksums));
PacketHeader header = pr.getHeader();
assertEquals(SEQNO, header.getSeqno());
assertEquals(OFFSET_IN_BLOCK, header.getOffsetInBlock());
assertEquals(dataLen + checksumsLen + Ints.BYTES, header.getPacketLen());
// Mirror the packet to an output stream and make sure it matches
// the packet we sent.
ByteArrayOutputStream mirrored = new ByteArrayOutputStream();
mirrored = Mockito.spy(mirrored);
pr.mirrorPacketTo(new DataOutputStream(mirrored));
// The write should be done in a single call. Otherwise we may hit
// nasty interactions with nagling (eg HDFS-4049).
Mockito.verify(mirrored, Mockito.times(1)).write(Mockito.<byte[]>any(), Mockito.anyInt(), Mockito.eq(packet.length));
Mockito.verifyNoMoreInteractions(mirrored);
assertArrayEquals(packet, mirrored.toByteArray());
}
use of java.io.ByteArrayOutputStream in project hadoop by apache.
the class TestMetadataVersionOutput method testMetadataVersionOutput.
@Test(timeout = 30000)
public void testMetadataVersionOutput() throws IOException {
initConfig();
dfsCluster = new MiniDFSCluster.Builder(conf).manageNameDfsDirs(false).numDataNodes(1).checkExitOnShutdown(false).build();
dfsCluster.waitClusterUp();
dfsCluster.shutdown(false);
initConfig();
final PrintStream origOut = System.out;
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream stdOut = new PrintStream(baos);
try {
System.setOut(stdOut);
try {
NameNode.createNameNode(new String[] { "-metadataVersion" }, conf);
} catch (Exception e) {
assertExceptionContains("ExitException", e);
}
/* Check if meta data version is printed correctly. */
final String verNumStr = HdfsServerConstants.NAMENODE_LAYOUT_VERSION + "";
assertTrue(baos.toString("UTF-8").contains("HDFS Image Version: " + verNumStr));
assertTrue(baos.toString("UTF-8").contains("Software format version: " + verNumStr));
} finally {
System.setOut(origOut);
}
}
Aggregations