Search in sources :

Example 46 with HazelcastException

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);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) IOUtil.copyFile(com.hazelcast.nio.IOUtil.copyFile) File(java.io.File) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with HazelcastException

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);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) IOUtil.copyFile(com.hazelcast.nio.IOUtil.copyFile) File(java.io.File) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with HazelcastException

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());
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HazelcastException(com.hazelcast.core.HazelcastException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with HazelcastException

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());
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HazelcastException(com.hazelcast.core.HazelcastException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 50 with HazelcastException

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());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastException(com.hazelcast.core.HazelcastException) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastException(com.hazelcast.core.HazelcastException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)57 IOException (java.io.IOException)18 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)11 TransactionException (com.hazelcast.transaction.TransactionException)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 File (java.io.File)8 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 OCallable (com.orientechnologies.common.util.OCallable)6 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 Collator (com.hazelcast.mapreduce.Collator)4 CombinerFactory (com.hazelcast.mapreduce.CombinerFactory)4 Mapper (com.hazelcast.mapreduce.Mapper)4