Search in sources :

Example 1 with UserAttributes

use of org.apache.geode.cache.client.internal.UserAttributes in project geode by apache.

the class ClientCacheFactoryJUnitTest method test003DPmultiplePool.

/**
   * Make sure if we have more than one pool that we do not have a default
   */
@Test
public void test003DPmultiplePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("p7");
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666).create("p6");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(null, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with UserAttributes

use of org.apache.geode.cache.client.internal.UserAttributes in project geode by apache.

the class ClientCacheFactoryJUnitTest method test002DPsinglePool.

/**
   * Make sure if we have a single pool that it will be used as the default
   */
@Test
public void test002DPsinglePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    Pool p = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("singlePool");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(p, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with UserAttributes

use of org.apache.geode.cache.client.internal.UserAttributes in project geode by apache.

the class CqServiceImpl method addToCqMap.

/**
   * Adds the given CQ and cqQuery object into the CQ map.
   */
void addToCqMap(CqQueryImpl cq) throws CqExistsException, CqException {
    // On server side cqName will be server side cqName.
    String sCqName = cq.getServerCqName();
    if (logger.isDebugEnabled()) {
        logger.debug("Adding to CQ Repository. CqName : {} ServerCqName : {}", cq.getName(), sCqName);
    }
    HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
    if (cqMap.containsKey(sCqName)) {
        throw new CqExistsException(LocalizedStrings.CqService_A_CQ_WITH_THE_GIVEN_NAME_0_ALREADY_EXISTS.toLocalizedString(sCqName));
    }
    synchronized (cqQueryMapLock) {
        HashMap<String, CqQueryImpl> tmpCqQueryMap = new HashMap<>(cqQueryMap);
        try {
            tmpCqQueryMap.put(sCqName, cq);
        } catch (Exception ex) {
            StringId errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_STORE_CONTINUOUS_QUERY_IN_THE_REPOSITORY_CQNAME_0_1;
            Object[] errMsgArgs = new Object[] { sCqName, ex.getLocalizedMessage() };
            String s = errMsg.toLocalizedString(errMsgArgs);
            logger.error(s);
            throw new CqException(s, ex);
        }
        UserAttributes attributes = UserAttributes.userAttributes.get();
        if (attributes != null) {
            this.cqNameToUserAttributesMap.put(cq.getName(), attributes);
        }
        cqQueryMap = tmpCqQueryMap;
    }
}
Also used : StringId(org.apache.geode.i18n.StringId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CqException(org.apache.geode.cache.query.CqException) CqExistsException(org.apache.geode.cache.query.CqExistsException) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes)

Aggregations

UserAttributes (org.apache.geode.cache.client.internal.UserAttributes)3 InetSocketAddress (java.net.InetSocketAddress)2 Properties (java.util.Properties)2 RegionService (org.apache.geode.cache.RegionService)2 ProxyCache (org.apache.geode.cache.client.internal.ProxyCache)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 TimeoutException (org.apache.geode.cache.TimeoutException)1 CqClosedException (org.apache.geode.cache.query.CqClosedException)1 CqException (org.apache.geode.cache.query.CqException)1 CqExistsException (org.apache.geode.cache.query.CqExistsException)1 QueryException (org.apache.geode.cache.query.QueryException)1