Search in sources :

Example 91 with HazelcastException

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

the class ClientICacheManagerTest method getCache_when_hazelcastExceptionIsThrown_then_isRethrown.

@Test
public void getCache_when_hazelcastExceptionIsThrown_then_isRethrown() {
    // when a HazelcastException occurs whose cause is not a ServiceNotFoundException
    HazelcastInstance hzInstance = mock(HazelcastInstance.class);
    when(hzInstance.getDistributedObject(anyString(), anyString())).thenThrow(new HazelcastException("mock exception"));
    ClientICacheManager clientCacheManager = new ClientICacheManager(hzInstance);
    // then the exception is rethrown
    thrown.expect(HazelcastException.class);
    clientCacheManager.getCache("any-cache");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastException(com.hazelcast.core.HazelcastException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 92 with HazelcastException

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

the class LoggingServiceImpl method setLevel.

/**
 * Sets the levels of all the loggers known to this logger service to
 * the given level. If a certain logger was already preconfigured with a more
 * verbose level than the given level, it will be kept at that more verbose
 * level.
 * <p>
 * WARNING: Keep in mind that verbose log levels like {@link Level#FINEST}
 * may severely affect the performance.
 *
 * @param level the level to set.
 * @throws HazelcastException if the underlying {@link LoggerFactory} doesn't
 *                            implement {@link InternalLoggerFactory} required
 *                            for dynamic log level changing.
 */
public void setLevel(@Nonnull Level level) {
    if (loggerFactory instanceof InternalLoggerFactory) {
        levelSet = level;
        ((InternalLoggerFactory) loggerFactory).setLevel(level);
        AuditlogService auditlogService = node.getNodeExtension().getAuditlogService();
        auditlogService.eventBuilder(AuditlogTypeIds.MEMBER_LOGGING_LEVEL_SET).message("Log level set.").addParameter("level", level).log();
    } else {
        throw new HazelcastException("Logger factory doesn't support dynamic log level changes: " + loggerFactory.getClass());
    }
}
Also used : AuditlogService(com.hazelcast.auditlog.AuditlogService) HazelcastException(com.hazelcast.core.HazelcastException)

Example 93 with HazelcastException

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

the class ServiceManagerImpl method registerService.

public synchronized void registerService(String serviceName, Object service) {
    if (logger.isFinestEnabled()) {
        logger.finest("Registering service: '" + serviceName + "'");
    }
    final ServiceInfo serviceInfo = new ServiceInfo(serviceName, service);
    final ServiceInfo currentServiceInfo = services.putIfAbsent(serviceName, serviceInfo);
    if (currentServiceInfo != null) {
        logger.warning("Replacing " + currentServiceInfo + " with " + serviceInfo);
        if (currentServiceInfo.isCoreService()) {
            throw new HazelcastException("Can not replace a CoreService! Name: " + serviceName + ", Service: " + currentServiceInfo.getService());
        }
        if (currentServiceInfo.isManagedService()) {
            shutdownService(currentServiceInfo.getService(), false);
        }
        services.put(serviceName, serviceInfo);
    }
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) HazelcastException(com.hazelcast.core.HazelcastException)

Example 94 with HazelcastException

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

the class ReliableTopicProxy method loadListener.

private MessageListener loadListener(ListenerConfig listenerConfig) {
    try {
        MessageListener listener = (MessageListener) listenerConfig.getImplementation();
        if (listener != null) {
            return listener;
        }
        if (listenerConfig.getClassName() != null) {
            Object object = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), listenerConfig.getClassName());
            if (!(object instanceof MessageListener)) {
                throw new HazelcastException("class '" + listenerConfig.getClassName() + "' is not an instance of " + MessageListener.class.getName());
            }
            listener = (MessageListener) object;
        }
        return listener;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) ReliableMessageListener(com.hazelcast.topic.ReliableMessageListener) MessageListener(com.hazelcast.topic.MessageListener) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) TopicOverloadException(com.hazelcast.topic.TopicOverloadException) HazelcastException(com.hazelcast.core.HazelcastException)

Example 95 with HazelcastException

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

the class SessionAwareSemaphoreReleaseAcquiredSessionsOnFailureTest method testAcquire_shouldReleaseSessionsOnRuntimeError.

@Test
public void testAcquire_shouldReleaseSessionsOnRuntimeError() throws InterruptedException {
    initSemaphoreAndAcquirePermits(10, 5);
    assertEquals(getSessionAcquireCount(), 5);
    Future future = spawn(() -> {
        Thread.currentThread().interrupt();
        semaphore.acquire(5);
    });
    try {
        future.get();
        fail("Acquire request should have been completed with InterruptedException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof HazelcastException);
        assertTrue(e.getCause().getCause() instanceof InterruptedException);
    }
    assertEquals(getSessionAcquireCount(), 5);
}
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)

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