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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations