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