Search in sources :

Example 36 with ServerConnectivityException

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);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) Pool(org.apache.geode.cache.client.Pool)

Example 37 with ServerConnectivityException

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);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) Pool(org.apache.geode.cache.client.Pool)

Example 38 with ServerConnectivityException

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);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) SocketTimeoutException(java.net.SocketTimeoutException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 39 with ServerConnectivityException

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);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SelectResults(org.apache.geode.cache.query.SelectResults) Set(java.util.Set) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) Region(org.apache.geode.cache.Region) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) 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 40 with ServerConnectivityException

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

ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)44 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)25 FunctionException (org.apache.geode.cache.execute.FunctionException)17 IOException (java.io.IOException)16 Region (org.apache.geode.cache.Region)13 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)12 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)10 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 CacheClosedException (org.apache.geode.cache.CacheClosedException)8 Pool (org.apache.geode.cache.client.Pool)6 ExecutablePool (org.apache.geode.cache.client.internal.ExecutablePool)6 Test (org.junit.Test)6 SocketTimeoutException (java.net.SocketTimeoutException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Execution (org.apache.geode.cache.execute.Execution)4