Search in sources :

Example 1 with Endpoint

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

the class ConnectionPoolDUnitTest method test033NotSerializableException.

// this test doesn't do anything so I commented it out
// /**
// * Tests that new connections update client notification connections.
// */
// public void test032NewConnections() throws Exception {
// final String name = this.getName();
// final Host host = Host.getHost(0);
// VM vm0 = host.getVM(0);
// VM vm1 = host.getVM(1);
// VM vm2 = host.getVM(2);
// // Cache server serves up the region
// vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
// public void run2() throws CacheException {
// AttributesFactory factory = getBridgeServerRegionAttributes(null,null);
// Region region = createRegion(name, factory.create());
// pause(1000);
// try {
// startBridgeServer(0);
// } catch (Exception ex) {
// fail("While starting CacheServer", ex);
// }
// }
// });
// final int port =
// vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
// final String host0 = getServerHostName(vm0.getHost());
// SerializableRunnable create =
// new CacheSerializableRunnable("Create region") {
// public void run2() throws CacheException {
// getCache();
// AttributesFactory factory = new AttributesFactory();
// factory.setScope(Scope.LOCAL);
// ClientServerTestCase.configureConnectionPool(factory,host0,port,-1,true,-1,-1, null);
// createRegion(name, factory.create());
// }
// };
// vm1.invoke(create);
// vm2.invoke(create);
// vm1.invoke(new CacheSerializableRunnable("Create new connection") {
// public void run2() throws CacheException {
// Region region = getRootRegion().getSubregion(name);
// BridgeClient writer = getPoolClient(region);
// Endpoint[] endpoints = (Endpoint[])writer.getEndpoints();
// for (int i=0; i<endpoints.length; i++) endpoints[i].addNewConnection();
// }
// });
// SerializableRunnable close =
// new CacheSerializableRunnable("Close Pool") {
// public void run2() throws CacheException {
// Region region = getRootRegion().getSubregion(name);
// region.localDestroyRegion();
// }
// };
// vm1.invoke(close);
// vm2.invoke(close);
// vm0.invoke(new SerializableRunnable("Stop CacheServer") {
// public void run() {
// stopBridgeServer(getCache());
// }
// });
// }
/**
   * Tests that creating, putting and getting a non-serializable key or value throws the correct
   * (NotSerializableException) exception.
   */
@Test
public void test033NotSerializableException() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // VM vm2 = host.getVM(2);
    vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
            createRegion(name, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    SerializableRunnable create = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getLonerSystem();
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setConcurrencyChecksEnabled(false);
            ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    };
    vm1.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Attempt to create a non-serializable value") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            try {
                region.create(new Integer(1), new ConnectionPoolTestNonSerializable());
                fail("Should not have been able to create a ConnectionPoolTestNonSerializable");
            } catch (Exception e) {
                if (!(e.getCause() instanceof java.io.NotSerializableException))
                    fail("Unexpected exception while creating a non-serializable value " + e);
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Attempt to put a non-serializable value") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            try {
                region.put(new Integer(1), new ConnectionPoolTestNonSerializable());
                fail("Should not have been able to put a ConnectionPoolTestNonSerializable");
            } catch (Exception e) {
                if (!(e.getCause() instanceof java.io.NotSerializableException))
                    fail("Unexpected exception while putting a non-serializable value " + e);
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Attempt to get a non-serializable key") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            try {
                region.get(new ConnectionPoolTestNonSerializable());
                fail("Should not have been able to get a ConnectionPoolTestNonSerializable");
            } catch (Exception e) {
                if (!(e.getCause() instanceof java.io.NotSerializableException))
                    fail("Unexpected exception while getting a non-serializable key " + e);
            }
        }
    });
    SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
        }
    };
    vm1.invoke(close);
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 2 with Endpoint

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

the class ConnectionPoolDUnitTest method outOfBalanceReport.

protected String outOfBalanceReport(PoolImpl pool) {
    StringBuffer result = new StringBuffer();
    Iterator it = pool.getEndpointMap().values().iterator();
    result.append("<");
    while (it.hasNext()) {
        Endpoint ep = (Endpoint) it.next();
        result.append("ep=" + ep);
        result.append(" conCount=" + ep.getStats().getConnections());
        if (it.hasNext()) {
            result.append(", ");
        }
    }
    result.append(">");
    return result.toString();
}
Also used : Endpoint(org.apache.geode.cache.client.internal.Endpoint) Iterator(java.util.Iterator)

Example 3 with Endpoint

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

the class CacheClientUpdater method processMessages.

/**
   * Processes messages received from the server.
   * 
   * Only certain types of messages are handled.
   *
   * TODO: Method 'processMessages' is too complex to analyze by data flow algorithm
   * 
   * @see MessageType#CLIENT_MARKER
   * @see MessageType#LOCAL_CREATE
   * @see MessageType#LOCAL_UPDATE
   * @see MessageType#LOCAL_INVALIDATE
   * @see MessageType#LOCAL_DESTROY
   * @see MessageType#LOCAL_DESTROY_REGION
   * @see MessageType#CLEAR_REGION
   * @see ClientUpdateMessage
   */
private void processMessages() {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    try {
        Message clientMessage = initializeMessage();
        if (quitting()) {
            if (isDebugEnabled) {
                logger.debug("processMessages quitting early because we have stopped");
            }
            // our caller calls close which will notify all waiters for our init
            return;
        }
        logger.info(LocalizedMessage.create(LocalizedStrings.CacheClientUpdater_0_READY_TO_PROCESS_MESSAGES, this));
        while (this.continueProcessing.get()) {
            if (quitting()) {
                if (isDebugEnabled) {
                    logger.debug("termination detected");
                }
                // our caller calls close which will notify all waiters for our init
                return;
            }
            // the endpoint died while this thread was sleeping.
            if (this.endpoint.isClosed()) {
                if (isDebugEnabled) {
                    logger.debug("endpoint died");
                }
                // = false;
                this.continueProcessing.set(false);
                break;
            }
            try {
                // Read the message
                clientMessage.recv();
                // Wait for the previously failed cache client updater
                // to finish. This will avoid out of order messages.
                waitForFailedUpdater();
                this.cache.waitForRegisterInterestsInProgress();
                if (quitting()) {
                    if (isDebugEnabled) {
                        logger.debug("processMessages quitting before processing message");
                    }
                    break;
                }
                // If the message is a ping, ignore it
                if (clientMessage.getMessageType() == MessageType.SERVER_TO_CLIENT_PING) {
                    if (isDebugEnabled) {
                        logger.debug("{}: Received ping", this);
                    }
                    continue;
                }
                boolean isDeltaSent = false;
                boolean isCreateOrUpdate = clientMessage.getMessageType() == MessageType.LOCAL_CREATE || clientMessage.getMessageType() == MessageType.LOCAL_UPDATE;
                if (isCreateOrUpdate) {
                    isDeltaSent = (Boolean) clientMessage.getPart(2).getObject();
                }
                // extract the eventId and verify if it is a duplicate event
                // if it is a duplicate event, ignore
                // @since GemFire 5.1
                int numberOfParts = clientMessage.getNumberOfParts();
                Part eid = clientMessage.getPart(numberOfParts - 1);
                // TODO the message handling methods also deserialized the eventID - inefficient
                EventID eventId = (EventID) eid.getObject();
                // no need to verify if the instantiator msg is duplicate or not
                if (clientMessage.getMessageType() != MessageType.REGISTER_INSTANTIATORS && clientMessage.getMessageType() != MessageType.REGISTER_DATASERIALIZERS) {
                    if (this.qManager.getState().verifyIfDuplicate(eventId, !(this.isDurableClient || isDeltaSent))) {
                        continue;
                    }
                }
                if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
                    logger.trace(LogMarker.BRIDGE_SERVER, "Processing event with id {}", eventId.expensiveToString());
                }
                this.isOpCompleted = true;
                // Process the message
                switch(clientMessage.getMessageType()) {
                    case MessageType.LOCAL_CREATE:
                    case MessageType.LOCAL_UPDATE:
                        handleUpdate(clientMessage);
                        break;
                    case MessageType.LOCAL_INVALIDATE:
                        handleInvalidate(clientMessage);
                        break;
                    case MessageType.LOCAL_DESTROY:
                        handleDestroy(clientMessage);
                        break;
                    case MessageType.LOCAL_DESTROY_REGION:
                        handleDestroyRegion(clientMessage);
                        break;
                    case MessageType.CLEAR_REGION:
                        handleClearRegion(clientMessage);
                        break;
                    case MessageType.REGISTER_INSTANTIATORS:
                        handleRegisterInstantiator(clientMessage, eventId);
                        break;
                    case MessageType.REGISTER_DATASERIALIZERS:
                        handleRegisterDataSerializer(clientMessage, eventId);
                        break;
                    case MessageType.CLIENT_MARKER:
                        handleMarker(clientMessage);
                        break;
                    case MessageType.INVALIDATE_REGION:
                        handleInvalidateRegion(clientMessage);
                        break;
                    case MessageType.CLIENT_REGISTER_INTEREST:
                        handleRegisterInterest(clientMessage);
                        break;
                    case MessageType.CLIENT_UNREGISTER_INTEREST:
                        handleUnregisterInterest(clientMessage);
                        break;
                    case MessageType.TOMBSTONE_OPERATION:
                        handleTombstoneOperation(clientMessage);
                        break;
                    default:
                        logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientUpdater_0_RECEIVED_AN_UNSUPPORTED_MESSAGE_TYPE_1, new Object[] { this, MessageType.getString(clientMessage.getMessageType()) }));
                        break;
                }
                if (this.isOpCompleted && (this.isDurableClient || isDeltaSent)) {
                    this.qManager.getState().verifyIfDuplicate(eventId, true);
                }
            // TODO we should maintain the client's "live" view of the server
            // but we don't because the server health monitor needs traffic
            // originating from the client
            // and by updating the last update stat, the ServerMonitor is less
            // likely to send pings...
            // and the ClientHealthMonitor will cause a disconnect
            } catch (InterruptedIOException ignore) {
                // Per Sun's support web site, this exception seems to be peculiar
                // to Solaris, and may eventually not even be generated there.
                //
                // When this exception is thrown, the thread has been interrupted, but
                // isInterrupted() is false. (How very odd!)
                //
                // We regard it the same as an InterruptedException
                this.continueProcessing.set(false);
                if (isDebugEnabled) {
                    logger.debug("InterruptedIOException");
                }
            } catch (IOException e) {
                // Either the server went away, or we caught a closing condition.
                if (!quitting()) {
                    // Server departed; print a message.
                    ClientServerObserver clientServerObserver = ClientServerObserverHolder.getInstance();
                    clientServerObserver.beforeFailoverByCacheClientUpdater(this.location);
                    this.eManager.serverCrashed(this.endpoint);
                    if (isDebugEnabled) {
                        logger.debug("Caught the following exception and will exit", e);
                    }
                }
                // !quitting
                // In any event, terminate this thread.
                this.continueProcessing.set(false);
                if (isDebugEnabled) {
                    logger.debug("terminated due to IOException");
                }
            } catch (Exception e) {
                if (!quitting()) {
                    ClientServerObserver clientServerObserver = ClientServerObserverHolder.getInstance();
                    clientServerObserver.beforeFailoverByCacheClientUpdater(this.location);
                    this.eManager.serverCrashed(this.endpoint);
                    String message = ": Caught the following exception and will exit: ";
                    handleException(message, e);
                }
                // In any event, terminate this thread.
                // = false; // force termination
                this.continueProcessing.set(false);
                if (isDebugEnabled) {
                    logger.debug("CCU terminated due to Exception");
                }
            } finally {
                clientMessage.clear();
            }
        }
    // while
    } finally {
        if (isDebugEnabled) {
            logger.debug("has stopped and cleaning the helper ..");
        }
        // added to fix some race conditions associated with 38382
        close();
        // this will make sure that if this thread dies without starting QueueMgr then it will start..
        // 1. above we ignore InterruptedIOException and this thread dies without informing QueueMgr
        // 2. if there is some other race condition with continueProcessing flag
        this.qManager.checkEndpoint(this, this.endpoint);
    }
}
Also used : ClientServerObserver(org.apache.geode.internal.cache.ClientServerObserver) InterruptedIOException(java.io.InterruptedIOException) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) EventID(org.apache.geode.internal.cache.EventID) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Aggregations

Endpoint (org.apache.geode.cache.client.internal.Endpoint)3 IOException (java.io.IOException)2 CancelException (org.apache.geode.CancelException)2 InterruptedIOException (java.io.InterruptedIOException)1 ConnectException (java.net.ConnectException)1 SocketException (java.net.SocketException)1 Iterator (java.util.Iterator)1 SSLException (javax.net.ssl.SSLException)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)1 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 ClientServerObserver (org.apache.geode.internal.cache.ClientServerObserver)1 EventID (org.apache.geode.internal.cache.EventID)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)1 LocalizedMessage (org.apache.geode.internal.logging.log4j.LocalizedMessage)1 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)1