Search in sources :

Example 1 with NoAvailableServersException

use of org.apache.geode.cache.client.NoAvailableServersException in project geode by apache.

the class ClientServerMiscDUnitTest method _createClientCache.

public static Pool _createClientCache(String h, boolean empty, int... ports) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    Cache cache = new ClientServerMiscDUnitTest().createCacheV(props);
    ClientServerMiscDUnitTest.static_cache = cache;
    PoolFactory poolFactory = PoolManager.createFactory();
    PoolImpl p = (PoolImpl) addServers(poolFactory, h, ports).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerMiscDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    if (empty) {
        factory.setDataPolicy(DataPolicy.EMPTY);
    }
    factory.setPoolName(p.getName());
    attrs = factory.create();
    Region region1 = cache.createRegion(REGION_NAME1, attrs);
    Region region2 = cache.createRegion(REGION_NAME2, attrs);
    Region prRegion = cache.createRegion(PR_REGION_NAME, attrs);
    assertNotNull(region1);
    assertNotNull(region2);
    assertNotNull(prRegion);
    pool = p;
    // conn = pool.acquireConnection();
    // assertNotNull(conn);
    // TODO does this WaitCriterion actually help?
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            try {
                conn = pool.acquireConnection();
                if (conn == null) {
                    excuse = "acquireConnection returned null?";
                    return false;
                }
                return true;
            } catch (NoAvailableServersException e) {
                excuse = "Cannot find a server: " + e;
                return false;
            }
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
    return p;
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Cache(org.apache.geode.cache.Cache)

Example 2 with NoAvailableServersException

use of org.apache.geode.cache.client.NoAvailableServersException in project geode by apache.

the class SecurityTestUtils method doFunctionExecuteP.

private static void doFunctionExecuteP(final int multiUserIndex, final Function function, int expectedResult, final String method) {
    Region region = null;
    try {
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNotNull(region);
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing function: " + ex);
        } else {
            fail("Got unexpected exception when executing function", ex);
        }
    }
    try {
        FunctionService.registerFunction(function);
        Execution execution = null;
        if ("region".equals(method)) {
            execution = FunctionService.onRegion(region);
        } else if ("server".equals(method)) {
            if (multiUserAuthMode) {
                execution = FunctionService.onServer(proxyCaches[multiUserIndex]);
            } else {
                execution = FunctionService.onServer(pool);
            }
        } else {
            // if ("servers".equals(method)) {
            if (multiUserAuthMode) {
                execution = FunctionService.onServers(proxyCaches[multiUserIndex]);
            } else {
                execution = FunctionService.onServers(pool);
            }
        }
        execution.execute(function.getId());
        if (expectedResult != NO_EXCEPTION) {
            fail("Expected a NotAuthorizedException while executing function");
        }
    } catch (NoAvailableServersException ex) {
        if (expectedResult == NO_AVAILABLE_SERVERS) {
            getLogWriter().info("Got expected NoAvailableServers when executing function: " + ex.getCause());
        } else {
            fail("Got unexpected exception when executing function", ex);
        }
    } catch (ServerConnectivityException ex) {
        if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
            getLogWriter().info("Got expected NotAuthorizedException when executing function: " + ex.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing function: " + ex);
        } else {
            fail("Got unexpected exception when executing function", ex);
        }
    } catch (FunctionException ex) {
        // ServerOperationException AND cause.cause is NotAuthorizedException))
        if (expectedResult == NOTAUTHZ_EXCEPTION && (ex.getCause() instanceof NotAuthorizedException || (ex.getCause() instanceof ServerOperationException && ex.getCause().getCause() instanceof NotAuthorizedException))) {
            getLogWriter().info("Got expected NotAuthorizedException when executing function: " + ex.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing function: " + ex);
        } else {
            fail("Got unexpected exception when executing function", ex);
        }
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing function: " + ex);
        } else {
            fail("Got unexpected exception when executing function", ex);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Execution(org.apache.geode.cache.execute.Execution) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) FunctionException(org.apache.geode.cache.execute.FunctionException) Region(org.apache.geode.cache.Region) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException)

Example 3 with NoAvailableServersException

use of org.apache.geode.cache.client.NoAvailableServersException in project geode by apache.

the class SecurityTestUtils method doRegionDestroysP.

private static void doRegionDestroysP(final int multiUserIndex, final int expectedResult) {
    Region region = null;
    try {
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNotNull(region);
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing region destroy: " + ex);
        } else {
            fail("Got unexpected exception when doing region destroy", ex);
        }
    }
    try {
        region.destroyRegion();
        if (expectedResult != NO_EXCEPTION) {
            fail("Expected a NotAuthorizedException while doing region destroy");
        }
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNull(region);
    } catch (NoAvailableServersException ex) {
        if (expectedResult == NO_AVAILABLE_SERVERS) {
            getLogWriter().info("Got expected NoAvailableServers when doing region destroy: " + ex.getCause());
        } else {
            fail("Got unexpected exception when doing region destroy", ex);
        }
    } catch (ServerConnectivityException ex) {
        if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
            getLogWriter().info("Got expected NotAuthorizedException when doing region destroy: " + ex.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing region destroy: " + ex);
        } else {
            fail("Got unexpected exception when doing region destroy", ex);
        }
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing region destroy: " + ex);
        } else {
            fail("Got unexpected exception when doing region destroy", ex);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) Region(org.apache.geode.cache.Region) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException)

Example 4 with NoAvailableServersException

use of org.apache.geode.cache.client.NoAvailableServersException in project geode by apache.

the class SecurityTestUtils method doQueryExecuteP.

private static void doQueryExecuteP(final int multiUserIndex, final int expectedResult, final int expectedValue) {
    Region region = null;
    try {
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNotNull(region);
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing query: " + ex);
        } else {
            fail("Got unexpected exception when executing query", ex);
        }
    }
    try {
        String queryString = "SELECT DISTINCT * FROM " + region.getFullPath();
        Query query = null;
        if (multiUserAuthMode) {
            query = proxyCaches[multiUserIndex].getQueryService().newQuery(queryString);
        } else {
            region.getCache().getQueryService().newQuery(queryString);
        }
        SelectResults result = (SelectResults) query.execute();
        if (expectedResult != NO_EXCEPTION) {
            fail("Expected a NotAuthorizedException while executing function");
        }
        assertEquals(expectedValue, result.asList().size());
    } catch (NoAvailableServersException ex) {
        if (expectedResult == NO_AVAILABLE_SERVERS) {
            getLogWriter().info("Got expected NoAvailableServers when executing query: " + ex.getCause());
        } else {
            fail("Got unexpected exception when executing query", ex);
        }
    } catch (ServerConnectivityException ex) {
        if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
            getLogWriter().info("Got expected NotAuthorizedException when executing query: " + ex.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing query: " + ex);
        } else {
            fail("Got unexpected exception when executing query", ex);
        }
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when executing query: " + ex);
        } else {
            fail("Got unexpected exception when executing query", ex);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) Region(org.apache.geode.cache.Region) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException)

Example 5 with NoAvailableServersException

use of org.apache.geode.cache.client.NoAvailableServersException in project geode by apache.

the class SecurityTestUtils method doInvalidatesP.

private static void doInvalidatesP(final int num, final int multiUserIndex, final int expectedResult) {
    assertTrue(num <= KEYS.length);
    Region region = null;
    try {
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNotNull(region);
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing invalidates: " + ex);
        } else {
            fail("Got unexpected exception when doing invalidates", ex);
        }
    }
    for (int index = 0; index < num; ++index) {
        try {
            region.invalidate(KEYS[index]);
            if (expectedResult != NO_EXCEPTION) {
                fail("Expected a NotAuthorizedException while doing invalidates");
            }
        } catch (NoAvailableServersException ex) {
            if (expectedResult == NO_AVAILABLE_SERVERS) {
                getLogWriter().info("Got expected NoAvailableServers when doing invalidates: " + ex.getCause());
                continue;
            } else {
                fail("Got unexpected exception when doing invalidates", ex);
            }
        } catch (ServerConnectivityException ex) {
            if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
                getLogWriter().info("Got expected NotAuthorizedException when doing invalidates: " + ex.getCause());
                continue;
            } else if (expectedResult == OTHER_EXCEPTION) {
                getLogWriter().info("Got expected exception when doing invalidates: " + ex);
            } else {
                fail("Got unexpected exception when doing invalidates", ex);
            }
        } catch (Exception ex) {
            if (expectedResult == OTHER_EXCEPTION) {
                getLogWriter().info("Got expected exception when doing invalidates: " + ex);
            } else {
                fail("Got unexpected exception when doing invalidates", ex);
            }
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) Region(org.apache.geode.cache.Region) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException)

Aggregations

NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)14 IOException (java.io.IOException)13 Region (org.apache.geode.cache.Region)11 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)10 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)10 FunctionException (org.apache.geode.cache.execute.FunctionException)10 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)10 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 CancelException (org.apache.geode.CancelException)2 Endpoint (org.apache.geode.cache.client.internal.Endpoint)2 SelectResults (org.apache.geode.cache.query.SelectResults)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)2 Host (org.apache.geode.test.dunit.Host)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 ArrayList (java.util.ArrayList)1