use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class IOUtilTest method testCopyFileFailsWhenTargetDoesntExistAndCannotBeCreated.
@Test
public void testCopyFileFailsWhenTargetDoesntExistAndCannotBeCreated() throws IOException {
final File target = mock(File.class);
when(target.exists()).thenReturn(false);
when(target.mkdirs()).thenReturn(false);
final File source = new File("source");
assertTrue(!source.exists());
source.createNewFile();
try {
copyFile(source, target, -1);
fail();
} catch (HazelcastException expected) {
EmptyStatement.ignore(expected);
}
delete(source);
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class IOUtilTest method testCopyFailsWhenSourceCannotBeListed.
@Test
public void testCopyFailsWhenSourceCannotBeListed() throws IOException {
final File source = mock(File.class);
when(source.exists()).thenReturn(true);
when(source.isDirectory()).thenReturn(true);
when(source.listFiles()).thenReturn(null);
when(source.getName()).thenReturn("dummy");
final File dest = new File("dest");
assertTrue(!dest.exists());
dest.mkdir();
try {
copy(source, dest);
fail();
} catch (HazelcastException expected) {
EmptyStatement.ignore(expected);
}
delete(dest);
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class AbstractInvocationFuture_GetSafely method whenRegularException.
@Test
public void whenRegularException() throws Exception {
Exception ex = new Exception();
future.complete(ex);
Future joinFuture = spawn(new Callable<Object>() {
@Override
public Object call() throws Exception {
return future.join();
}
});
assertCompletesEventually(joinFuture);
try {
joinFuture.get();
fail();
} catch (ExecutionException e) {
// The 'ex' is wrapped in an unchecked HazelcastException
HazelcastException hzEx = assertInstanceOf(HazelcastException.class, e.getCause());
assertSame(ex, hzEx.getCause());
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class AbstractInvocationFuture_JoinTest method whenRegularException.
@Test
public void whenRegularException() throws Exception {
Exception ex = new Exception();
future.complete(ex);
Future joinFuture = spawn(new Callable<Object>() {
@Override
public Object call() throws Exception {
return future.join();
}
});
assertCompletesEventually(joinFuture);
try {
joinFuture.get();
fail();
} catch (ExecutionException e) {
// The 'ex' is wrapped in an unchecked HazelcastException
HazelcastException hzEx = assertInstanceOf(HazelcastException.class, e.getCause());
assertSame(ex, hzEx.getCause());
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class AbstractInvocationFuture_JoinTest method whenInterrupted.
@Test
public void whenInterrupted() throws Exception {
final AtomicReference<Thread> thread = new AtomicReference<Thread>();
final AtomicBoolean interrupted = new AtomicBoolean();
Future getFuture = spawn(new Callable<Object>() {
@Override
public Object call() throws Exception {
thread.set(Thread.currentThread());
try {
return future.join();
} finally {
interrupted.set(Thread.currentThread().isInterrupted());
}
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotSame(VOID, future.getState());
}
});
sleepSeconds(5);
thread.get().interrupt();
assertCompletesEventually(getFuture);
assertTrue(interrupted.get());
try {
future.join();
fail();
} catch (HazelcastException e) {
assertInstanceOf(InterruptedException.class, e.getCause());
}
}
Aggregations