use of org.junit.AssumptionViolatedException in project jacoco by jacoco.
the class InstrumenterTest method testInstrumentAll_Pack200.
@Test
public void testInstrumentAll_Pack200() throws IOException {
try {
Class.forName("java.util.jar.Pack200");
} catch (ClassNotFoundException e) {
throw new AssumptionViolatedException("this test requires JDK with Pack200");
}
ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream();
ZipOutputStream zipout = new ZipOutputStream(jarbuffer);
zipout.putNextEntry(new ZipEntry("Test.class"));
zipout.write(TargetLoader.getClassDataAsBytes(getClass()));
zipout.finish();
ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream();
GZIPOutputStream gzipOutput = new GZIPOutputStream(pack200buffer);
Pack200Streams.pack(jarbuffer.toByteArray(), gzipOutput);
gzipOutput.finish();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int count = instrumenter.instrumentAll(new ByteArrayInputStream(pack200buffer.toByteArray()), out, "Test");
assertEquals(1, count);
ZipInputStream zipin = new ZipInputStream(Pack200Streams.unpack(new GZIPInputStream(new ByteArrayInputStream(out.toByteArray()))));
assertEquals("Test.class", zipin.getNextEntry().getName());
assertNull(zipin.getNextEntry());
}
use of org.junit.AssumptionViolatedException in project jacoco by jacoco.
the class ContentTypeDetectorTest method testPack200File.
@Test
public void testPack200File() throws IOException {
try {
Class.forName("java.util.jar.Pack200");
} catch (ClassNotFoundException e) {
throw new AssumptionViolatedException("this test requires JDK with Pack200");
}
final ByteArrayOutputStream zipbuffer = new ByteArrayOutputStream();
final ZipOutputStream zip = new ZipOutputStream(zipbuffer);
zip.putNextEntry(new ZipEntry("hello.txt"));
zip.write("Hello Zip!".getBytes());
zip.close();
final ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream();
Pack200Streams.pack(zipbuffer.toByteArray(), pack200buffer);
initData(pack200buffer.toByteArray());
assertEquals(ContentTypeDetector.PACK200FILE, detector.getType());
assertContent();
}
use of org.junit.AssumptionViolatedException in project ignite by apache.
the class GridAbstractTest method runTest.
/**
* Runs test with the provided scenario.
*/
private void runTest(Statement testRoutine) throws Throwable {
prepareTestEnviroment();
try {
final AtomicReference<Throwable> ex = new AtomicReference<>();
Thread runner = new IgniteThread(getTestIgniteInstanceName(), "test-runner", new Runnable() {
@Override
public void run() {
try {
testRoutine.evaluate();
} catch (Throwable e) {
IgniteClosure<Throwable, Throwable> hnd = errorHandler();
ex.set(hnd != null ? hnd.apply(e) : e);
}
}
});
runner.start();
runner.join(isDebug() ? 0 : getTestTimeout());
if (runner.isAlive()) {
U.error(log, "Test has been timed out and will be interrupted (threads dump will be taken before interruption) [" + "test=" + getName() + ", timeout=" + getTestTimeout() + ']');
List<Ignite> nodes = IgnitionEx.allGridsx();
for (Ignite node : nodes) ((IgniteKernal) node).dumpDebugInfo();
// We dump threads to stdout, because we can loose logs in case
// the build is cancelled on TeamCity.
U.dumpThreads(null);
U.dumpThreads(log);
U.interrupt(runner);
U.join(runner, log);
throw new TimeoutException("Test has been timed out [test=" + getName() + ", timeout=" + getTestTimeout() + ']');
}
Throwable t = ex.get();
if (t != null) {
if (t instanceof AssumptionViolatedException)
U.quietAndInfo(log, "Test ignored [test=" + testDescription() + ", msg=" + t.getMessage() + "]");
else {
U.error(log, "Test failed [test=" + testDescription() + ", duration=" + (System.currentTimeMillis() - ts) + "]", t);
}
throw t;
}
assert !stopGridErr : "Error occurred on grid stop (see log for more details).";
} finally {
try {
cleanUpTestEnviroment();
} catch (Exception e) {
log.error("Failed to execute tear down after test (will ignore)", e);
}
}
}
use of org.junit.AssumptionViolatedException in project vert.x by eclipse.
the class FileSystemTest method testCopyFileAttributes.
@Test
public void testCopyFileAttributes() throws Exception {
String source = "foo.txt";
String target = "bar.txt";
createFileWithJunk(source, 100);
try {
Files.setPosixFilePermissions(new File(testDir, source).toPath(), EnumSet.of(PosixFilePermission.OWNER_READ));
} catch (UnsupportedOperationException e) {
throw new AssumptionViolatedException("POSIX file perms unsupported");
}
FileSystem fs = vertx.fileSystem();
String from = testDir + pathSep + source;
String to = testDir + pathSep + target;
CopyOptions options = new CopyOptions().setCopyAttributes(false);
fs.copy(from, to, options, onSuccess(v -> {
fs.props(from, onSuccess(expected -> {
fs.props(from, onSuccess(actual -> {
assertEquals(expected.creationTime(), actual.creationTime());
assertEquals(expected.lastModifiedTime(), actual.lastModifiedTime());
vertx.<Set<PosixFilePermission>>executeBlocking(fut -> {
try {
fut.complete(Files.getPosixFilePermissions(new File(testDir, target).toPath(), LinkOption.NOFOLLOW_LINKS));
} catch (IOException e) {
fut.fail(e);
}
}, onSuccess(perms -> {
assertEquals(EnumSet.of(PosixFilePermission.OWNER_READ), perms);
complete();
}));
}));
}));
}));
await();
}
use of org.junit.AssumptionViolatedException in project Payara by payara.
the class DirConfigSourceTest method testPropertyWatcher_RunFilesNewUpdate.
@Test
public void testPropertyWatcher_RunFilesNewUpdate() throws Exception {
// given
writeFile(subpath("watcher-files", "foobar"), "test");
writeFile(subpath("watcher-files", ".hidden", "foobar"), "hidden");
try {
Files.createSymbolicLink(subpath("watcher-files", "revealed"), subpath("watcher-files", ".hidden", "foobar"));
} catch (FileSystemException fileSystemException) {
if (OS.isWindows() && fileSystemException.getReason().contains("A required privilege is not held by the client")) {
throw new AssumptionViolatedException("Permissions to create Symbolic Links not granted", fileSystemException);
}
}
DirConfigSource.DirPropertyWatcher watcher = source.createWatcher(subpath("watcher-files"));
exec.scheduleWithFixedDelay(watcher, 0, 10, TimeUnit.MILLISECONDS);
assertEquals("test", source.getValue("watcher-files.foobar"));
assertEquals("hidden", source.getValue("watcher-files.revealed"));
// when
writeFile(subpath("watcher-files", "foobar"), "test2");
writeFile(subpath("watcher-files", "example"), "test2");
writeFile(subpath("watcher-files", "reveal", ".hidden"), "test2");
writeFile(subpath("watcher-files", ".hidden", "foobar"), "showme");
Files.delete(subpath("watcher-files", "revealed"));
Files.createSymbolicLink(subpath("watcher-files", "revealed"), subpath("watcher-files", ".hidden", "foobar"));
Thread.sleep(100);
// then
assertEquals("test2", source.getValue("watcher-files.foobar"));
assertEquals("test2", source.getValue("watcher-files.example"));
assertEquals("showme", source.getValue("watcher-files.revealed"));
assertEquals(null, source.getValue("watcher-files.reveal.hidden"));
}
Aggregations