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