Search in sources :

Example 96 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreReleaseAcquiredSessionsOnFailureTest method testTryAcquire_shouldReleaseSessionsOnRuntimeError.

@Test
public void testTryAcquire_shouldReleaseSessionsOnRuntimeError() throws InterruptedException {
    initSemaphoreAndAcquirePermits(2, 1);
    assertEquals(getSessionAcquireCount(), 1);
    Future future = spawn(() -> {
        Thread.currentThread().interrupt();
        semaphore.tryAcquire(10, TimeUnit.MINUTES);
    });
    try {
        future.get();
        fail("TryAcquire request should have been completed with InterruptedException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof HazelcastException);
        assertTrue(e.getCause().getCause() instanceof InterruptedException);
    }
    assertEquals(getSessionAcquireCount(), 1);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 97 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreReleaseAcquiredSessionsOnFailureTest method testDrainPermits_shouldReleaseSessionsOnRuntimeError.

@Test
public void testDrainPermits_shouldReleaseSessionsOnRuntimeError() throws InterruptedException {
    initSemaphoreAndAcquirePermits(42, 2);
    assertEquals(getSessionAcquireCount(), 2);
    Future future = spawn(() -> {
        Thread.currentThread().interrupt();
        semaphore.drainPermits();
    });
    try {
        future.get();
        fail("DrainPermits request should have been completed with InterruptedException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof HazelcastException);
        assertTrue(e.getCause().getCause() instanceof InterruptedException);
    }
    assertEquals(getSessionAcquireCount(), 2);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 98 with HazelcastException

use of com.hazelcast.core.HazelcastException in project Payara by payara.

the class HazelcastSymmetricEncryptor method objectToByteArray.

public static byte[] objectToByteArray(Object object) {
    byte[] bytes = null;
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bos)) {
        out.writeObject(object);
        bytes = bos.toByteArray();
    } catch (IOException ioe) {
    // See "if (bytes == null)"
    }
    if (bytes == null) {
        throw new HazelcastException("Error converting Object to Byte Array");
    }
    return bytes;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 99 with HazelcastException

use of com.hazelcast.core.HazelcastException in project Payara by payara.

the class HazelcastSymmetricEncryptor method encode.

public static byte[] encode(byte[] value) {
    // Generate IV.
    byte[] saltBytes = new byte[20];
    random.nextBytes(saltBytes);
    try {
        // Encrypting the data
        Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        AlgorithmParameters params = cipher.getParameters();
        byte[] ivBytes = params.getParameterSpec(IvParameterSpec.class).getIV();
        byte[] encryptedTextBytes = cipher.doFinal(value);
        // Prepend salt and IV
        byte[] buffer = new byte[saltBytes.length + ivBytes.length + encryptedTextBytes.length];
        System.arraycopy(saltBytes, 0, buffer, 0, saltBytes.length);
        System.arraycopy(ivBytes, 0, buffer, saltBytes.length, ivBytes.length);
        System.arraycopy(encryptedTextBytes, 0, buffer, saltBytes.length + ivBytes.length, encryptedTextBytes.length);
        return buffer;
    } catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException | IllegalBlockSizeException | InvalidParameterSpecException | BadPaddingException exception) {
        throw new HazelcastException(exception);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 100 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class QueueContainer method txnPeek.

/**
 * Retrieves, but does not remove, the head of the queue. If the queue is empty checks if there is a reserved item with
 * the associated {@code offerId} and returns it.
 * If the item was retrieved from the queue but does not contain any data and the queue store is enabled, this method will
 * try load the data from the data store.
 *
 * @param offerId       the ID of the reserved item to be returned if the queue is empty
 * @param transactionId currently ignored
 * @return the head of the queue or a reserved item associated with the {@code offerId} if the queue is empty
 * @throws HazelcastException if there is an exception while loading the data from the queue store
 */
public QueueItem txnPeek(long offerId, UUID transactionId) {
    QueueItem item = getItemQueue().peek();
    if (item == null) {
        if (offerId == -1) {
            return null;
        }
        TxQueueItem txItem = txMap.get(offerId);
        if (txItem == null) {
            return null;
        }
        item = new QueueItem(this, txItem.getItemId(), txItem.getSerializedObject());
        return item;
    }
    if (store.isEnabled() && item.getSerializedObject() == null) {
        try {
            load(item);
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    return item;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TransactionException(com.hazelcast.transaction.TransactionException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)123 IOException (java.io.IOException)43 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)14 TransactionException (com.hazelcast.transaction.TransactionException)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 File (java.io.File)13 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 Data (com.hazelcast.internal.serialization.Data)7 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)6 Future (java.util.concurrent.Future)6 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)5 OException (com.orientechnologies.common.exception.OException)5 OIOException (com.orientechnologies.common.io.OIOException)5 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)5 EOFException (java.io.EOFException)5 ArrayList (java.util.ArrayList)5