use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientTypeRegistration method processEnumInfoForEnumId.
private int processEnumInfoForEnumId(EnumInfo enumInfo) {
Collection<Pool> pools = getAllPools();
ServerConnectivityException lastException = null;
for (Pool pool : pools) {
try {
int result = GetPDXIdForEnumOp.execute((ExecutablePool) pool, enumInfo);
sendEnumIdToPool(enumInfo, result, pool);
return result;
} catch (ServerConnectivityException e) {
// ignore, try the next pool.
lastException = e;
}
}
throw returnCorrectExceptionForFailure(pools, -1, lastException);
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientTypeRegistration method getEnumById.
public EnumInfo getEnumById(int enumId) {
Collection<Pool> pools = getAllPools();
ServerConnectivityException lastException = null;
for (Pool pool : pools) {
try {
EnumInfo result = GetPDXEnumByIdOp.execute((ExecutablePool) pool, enumId);
if (result != null) {
return result;
}
} catch (ServerConnectivityException e) {
logger.debug("Received an exception getting pdx type from pool {}, {}", pool, e.getMessage(), e);
// ignore, try the next pool.
lastException = e;
}
}
throw returnCorrectExceptionForFailure(pools, enumId, lastException);
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class OpExecutorImplJUnitTest method testExecuteOn.
@Test
public void testExecuteOn() throws Exception {
OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, false, cancelCriterion, null);
ServerLocation server = new ServerLocation("localhost", -1);
Object result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
return "hello";
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
assertEquals("hello", result);
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(0, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new SocketTimeoutException();
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerConnectivityException expected) {
// do nothing
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(1, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new ServerOperationException("Something didn't work");
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerOperationException expected) {
// do nothing
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(0, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
{
final String expectedEx = "java.lang.Exception";
final String addExpected = "<ExpectedException action=add>" + expectedEx + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expectedEx + "</ExpectedException>";
logger.info(addExpected);
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new Exception("Something didn't work");
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerConnectivityException expected) {
// do nothing
} finally {
logger.info(removeExpected);
}
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(1, invalidateConnections);
assertEquals(1, serverCrashes);
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class SecurityTestUtils method doQueriesP.
private static void doQueriesP(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 doing queries: " + ex);
} else {
fail("Got unexpected exception when doing queries", ex);
}
}
String queryStr = "SELECT DISTINCT * FROM " + region.getFullPath();
try {
SelectResults queryResults = region.query(queryStr);
Set resultSet = queryResults.asSet();
assertEquals(expectedValue, resultSet.size());
if (expectedResult != NO_EXCEPTION) {
fail("Expected a NotAuthorizedException while doing queries");
}
} catch (NoAvailableServersException ex) {
if (expectedResult == NO_AVAILABLE_SERVERS) {
getLogWriter().info("Got expected NoAvailableServers when doing queries: " + ex.getCause());
} else {
fail("Got unexpected exception when doing queries", ex);
}
} catch (ServerConnectivityException ex) {
if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
getLogWriter().info("Got expected NotAuthorizedException when doing queries: " + ex.getCause());
} else if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing queries: " + ex);
} else {
fail("Got unexpected exception when doing queries", ex);
}
} catch (QueryInvocationTargetException qite) {
if ((expectedResult == NOTAUTHZ_EXCEPTION) && (qite.getCause() instanceof NotAuthorizedException)) {
getLogWriter().info("Got expected NotAuthorizedException when doing queries: " + qite.getCause());
} else if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing queries: " + qite);
} else {
fail("Got unexpected exception when doing queries", qite);
}
} catch (Exception ex) {
if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing queries: " + ex);
} else {
fail("Got unexpected exception when doing queries", ex);
}
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class SecurityTestUtils method doGetsP.
private static void doGetsP(final int num, final int multiUserIndex, final int expectedResult, final boolean newVals) {
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 gets: " + ex);
} else {
fail("Got unexpected exception when doing gets", ex);
}
}
for (int index = 0; index < num; ++index) {
Object value = null;
try {
try {
region.localInvalidate(KEYS[index]);
} catch (Exception ex) {
}
value = region.get(KEYS[index]);
if (expectedResult != NO_EXCEPTION) {
fail("Expected a NotAuthorizedException while doing gets");
}
} catch (NoAvailableServersException ex) {
if (expectedResult == NO_AVAILABLE_SERVERS) {
getLogWriter().info("Got expected NoAvailableServers when doing gets: " + ex.getCause());
continue;
} else {
fail("Got unexpected exception when doing gets", ex);
}
} catch (ServerConnectivityException ex) {
if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
getLogWriter().info("Got expected NotAuthorizedException when doing gets: " + ex.getCause());
continue;
} else if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing gets: " + ex);
} else {
fail("Got unexpected exception when doing gets", ex);
}
} catch (Exception ex) {
if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing gets: " + ex);
} else {
fail("Got unexpected exception when doing gets", ex);
}
}
assertNotNull(value);
if (newVals) {
assertEquals(NVALUES[index], value);
} else {
assertEquals(VALUES[index], value);
}
}
}
Aggregations