use of org.apache.commons.io.output.ByteArrayOutputStream in project indy by Commonjava.
the class StoreAndVerifyJarViaDirectDownloadTest method storeFileThenDownloadAndVerifyContentViaDirectDownload.
@Test
public void storeFileThenDownloadAndVerifyContentViaDirectDownload() throws Exception {
final String content = "This is a test: " + System.nanoTime();
String entryName = "org/something/foo.class";
ByteArrayOutputStream out = new ByteArrayOutputStream();
JarOutputStream jarOut = new JarOutputStream(out);
jarOut.putNextEntry(new JarEntry(entryName));
jarOut.write(content.getBytes());
jarOut.close();
// Used to visually inspect the jars moving up...
// String userDir = System.getProperty( "user.home" );
// File dir = new File( userDir, "temp" );
// dir.mkdirs();
//
// FileUtils.writeByteArrayToFile( new File( dir, name.getMethodName() + "-in.jar" ), out.toByteArray() );
final InputStream stream = new ByteArrayInputStream(out.toByteArray());
final String path = "/path/to/" + getClass().getSimpleName() + "-" + name.getMethodName() + ".jar";
assertThat(client.content().exists(hosted, STORE, path), equalTo(false));
client.content().store(hosted, STORE, path, stream);
assertThat(client.content().exists(hosted, STORE, path), equalTo(true));
final URL url = new URL(client.content().contentUrl(hosted, STORE, path));
final InputStream is = url.openStream();
byte[] result = IOUtils.toByteArray(is);
is.close();
assertThat(result, equalTo(out.toByteArray()));
// ...and down
// FileUtils.writeByteArrayToFile( new File( dir, name.getMethodName() + "-out.jar" ), result );
JarInputStream jarIn = new JarInputStream(new ByteArrayInputStream(result));
JarEntry jarEntry = jarIn.getNextJarEntry();
assertThat(jarEntry.getName(), equalTo(entryName));
String contentResult = IOUtils.toString(jarIn);
assertThat(contentResult, equalTo(content));
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hadoop by apache.
the class TestHsJobBlock method testHsJobBlockForNormalSizeJobShouldNotDisplayWarningMessage.
@Test
public void testHsJobBlockForNormalSizeJobShouldNotDisplayWarningMessage() {
Configuration config = new Configuration();
config.setInt(JHAdminConfig.MR_HS_LOADED_JOBS_TASKS_MAX, -1);
JobHistory jobHistory = new JobHitoryStubWithAllNormalSizeJobs();
jobHistory.init(config);
HsJobBlock jobBlock = new HsJobBlock(jobHistory) {
// override this so that the 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;
}
// override this to avoid view context lookup in render()
@Override
public ResponseInfo info(String about) {
return new ResponseInfo().about(about);
}
// override this to avoid view context lookup in render()
@Override
public String url(String... parts) {
return StringHelper.ujoin("", parts);
}
};
// 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 job overview for the job.", out.contains("ApplicationMaster"));
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project geode by apache.
the class MessageIdExtractorTest method byteArrayFromIds.
private byte[] byteArrayFromIds(Long connectionId, Long uniqueId) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dis = new DataOutputStream(byteArrayOutputStream);
dis.writeLong(connectionId);
dis.writeLong(uniqueId);
dis.flush();
return byteArrayOutputStream.toByteArray();
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testMixedMessages.
@Test
public void testMixedMessages() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
Exception ex2 = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex2);
LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event4 = getLoggingEventForTest("Test Exception.", ex2);
appender.append(event1);
appender.append(event2);
appender.append(event3);
appender.append(event4);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
if (m.matches()) {
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(2, StringUtils.countMatches(logging, stackTraceKey));
}
m.matches();
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(2, StringUtils.countMatches(logging, stackTraceKey));
}
} else {
fail("Didn't find proper logging pattern.");
}
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testDistinctLogMessages.
@Test
public void testDistinctLogMessages() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
Exception ex2 = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex2);
appender.append(event1);
appender.append(event2);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
if (m.matches()) {
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(1, StringUtils.countMatches(logging, stackTraceKey));
}
m.matches();
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(1, StringUtils.countMatches(logging, stackTraceKey));
}
} else {
fail("Didn't find proper logging pattern.");
}
}
Aggregations