use of org.eclipse.scout.rt.platform.util.Assertions.AssertionException in project scout.rt by eclipse.
the class JobCancelTest method testShutdownJobManagerAndSchedule.
@Test
public void testShutdownJobManagerAndSchedule() throws InterruptedException {
// Use dedicated job manager because job manager is shutdown in tests.
IBean<IJobManager> jobManagerBean = JobTestUtil.replaceCurrentJobManager(new JobManager() {
});
try {
// synchronized because modified/read by different threads.
final Set<String> protocol = Collections.synchronizedSet(new HashSet<String>());
final BlockingCountDownLatch latch = new BlockingCountDownLatch(2);
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add("running-1");
try {
latch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-1");
} finally {
protocol.add("done-1");
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
IFuture<Void> future2 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add("running-2");
try {
latch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-2");
} finally {
protocol.add("done-2");
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
assertTrue(latch.await());
// SHUTDOWN
Jobs.getJobManager().shutdown();
try {
Jobs.schedule(mock(IRunnable.class), Jobs.newInput());
fail("AssertionError expected");
} catch (AssertionException e) {
// NOOP
}
// VERIFY
assertEquals(CollectionUtility.hashSet("running-1", "running-2", "interrupted-1", "interrupted-2", "done-1", "done-2"), protocol);
future2.awaitDone(1, TimeUnit.SECONDS);
assertTrue(future2.isCancelled());
} finally {
JobTestUtil.unregisterAndShutdownJobManager(jobManagerBean);
}
}
use of org.eclipse.scout.rt.platform.util.Assertions.AssertionException in project scout.rt by eclipse.
the class JobManagerTest method testShutdown.
@Test
public void testShutdown() throws Exception {
// synchronized because modified/read by different threads.
final Set<String> protocol = Collections.synchronizedSet(new HashSet<String>());
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(3);
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(3);
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-1");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-2");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-3");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
assertTrue(setupLatch.await());
// RUN THE TEST
Jobs.getJobManager().shutdown();
// VERIFY
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.hashSet("interrupted-1", "interrupted-2", "interrupted-3"), protocol);
try {
Jobs.schedule(mock(IRunnable.class), Jobs.newInput());
fail("AssertionError expected");
} catch (AssertionException e) {
// NOOP
}
}
use of org.eclipse.scout.rt.platform.util.Assertions.AssertionException in project scout.rt by eclipse.
the class MutualExclusionTest method testMutexDeadlock.
/**
* Tests that a model-job cannot wait for a scheduled job.
*/
@Test
public void testMutexDeadlock() {
// synchronized because modified/read by different threads.
final List<Integer> protocol = Collections.synchronizedList(new ArrayList<Integer>());
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(1);
IFuture<Void> future = ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(3);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
try {
future.awaitDoneAndGet(1, TimeUnit.SECONDS, DefaultExceptionTranslator.class);
} catch (AssertionException e) {
protocol.add(2);
} catch (Exception e) {
protocol.add(4);
}
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
awaitDoneElseFail(JOB_IDENTIFIER);
assertEquals(CollectionUtility.arrayList(1, 2, 3), protocol);
}
use of org.eclipse.scout.rt.platform.util.Assertions.AssertionException in project scout.rt by eclipse.
the class MutualExclusionTest method testNestedModelJobs.
/**
* Tests serial execution of nested model jobs.
*/
@Test
public void testNestedModelJobs() {
// synchronized because modified/read by different threads.
final List<Integer> protocol = Collections.synchronizedList(new ArrayList<Integer>());
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(1);
// SCHEDULE
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(4);
// SCHEDULE
IFuture<Void> future = ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(9);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
try {
future.awaitDoneAndGet(1, TimeUnit.SECONDS);
} catch (AssertionException e) {
protocol.add(5);
}
protocol.add(6);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
protocol.add(2);
// SCHEDULE
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(7);
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add(10);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
protocol.add(8);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
protocol.add(3);
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
awaitDoneElseFail(JOB_IDENTIFIER);
assertEquals(CollectionUtility.arrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), protocol);
}
use of org.eclipse.scout.rt.platform.util.Assertions.AssertionException in project scout.rt by eclipse.
the class SunSecurityProvider method createHash.
@Override
public byte[] createHash(InputStream data, byte[] salt, int iterations) {
if (data == null) {
throw new AssertionException("no data provided");
}
try {
MessageDigest digest = MessageDigest.getInstance(getDigestAlgorithm(), getDigestAlgorithmProvider());
digest.reset();
if (salt != null && salt.length > 0) {
digest.update(salt);
}
int n;
byte[] buf = new byte[BUF_SIZE];
while ((n = data.read(buf)) >= 0) {
digest.update(buf, 0, n);
}
byte[] key = digest.digest();
for (int i = 1; i < iterations; i++) {
key = digest.digest(key);
digest.reset();
}
return key;
} catch (NoSuchAlgorithmException | NoSuchProviderException | IOException e) {
throw new ProcessingException("Unable to hash.", e);
}
}
Aggregations