Search in sources :

Example 1 with ClientServiceNotFoundException

use of com.hazelcast.client.spi.impl.ClientServiceNotFoundException in project hazelcast by hazelcast.

the class ClientICacheManagerTest method getCache_when_clientServiceNotFoundExceptionIsThrown_then_illegalStateExceptionIsThrown.

@Test
public void getCache_when_clientServiceNotFoundExceptionIsThrown_then_illegalStateExceptionIsThrown() {
    // when ClientServiceNotFoundException was thrown by hzInstance.getDistributedObject
    // (i.e. cache support is not available on the client-side)
    HazelcastInstance hzInstance = mock(HazelcastInstance.class);
    when(hzInstance.getDistributedObject(anyString(), anyString())).thenThrow(new ClientServiceNotFoundException("mock exception"));
    ClientICacheManager clientCacheManager = new ClientICacheManager(hzInstance);
    // then an IllegalStateException will be thrown by getCache
    thrown.expect(IllegalStateException.class);
    clientCacheManager.getCache("any-cache");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientServiceNotFoundException(com.hazelcast.client.spi.impl.ClientServiceNotFoundException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with ClientServiceNotFoundException

use of com.hazelcast.client.spi.impl.ClientServiceNotFoundException in project hazelcast by hazelcast.

the class ProxyManager method getOrCreateProxy.

public ClientProxy getOrCreateProxy(String service, String id) {
    final ObjectNamespace ns = new DefaultObjectNamespace(service, id);
    ClientProxyFuture proxyFuture = proxies.get(ns);
    if (proxyFuture != null) {
        return proxyFuture.get();
    }
    final ClientProxyFactory factory = proxyFactories.get(service);
    if (factory == null) {
        throw new ClientServiceNotFoundException("No factory registered for service: " + service);
    }
    final ClientProxy clientProxy = factory.create(id);
    proxyFuture = new ClientProxyFuture();
    final ClientProxyFuture current = proxies.putIfAbsent(ns, proxyFuture);
    if (current != null) {
        return current.get();
    }
    try {
        initializeWithRetry(clientProxy);
    } catch (Throwable e) {
        proxies.remove(ns);
        proxyFuture.set(e);
        throw ExceptionUtil.rethrow(e);
    }
    proxyFuture.set(clientProxy);
    return clientProxy;
}
Also used : DefaultObjectNamespace(com.hazelcast.spi.DefaultObjectNamespace) ClientServiceNotFoundException(com.hazelcast.client.spi.impl.ClientServiceNotFoundException) DefaultObjectNamespace(com.hazelcast.spi.DefaultObjectNamespace) ObjectNamespace(com.hazelcast.spi.ObjectNamespace)

Aggregations

ClientServiceNotFoundException (com.hazelcast.client.spi.impl.ClientServiceNotFoundException)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 DefaultObjectNamespace (com.hazelcast.spi.DefaultObjectNamespace)1 ObjectNamespace (com.hazelcast.spi.ObjectNamespace)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1