Search in sources :

Example 6 with ClientUpdateMessageImpl

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl in project geode by apache.

the class RequestEventValue method cmdExecute.

public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
    Part eventIDPart = null, valuePart = null;
    EventID event = null;
    Object callbackArg = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    StringBuffer errMessage = new StringBuffer();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    // Retrieve the data from the message parts
    int parts = clientMessage.getNumberOfParts();
    eventIDPart = clientMessage.getPart(0);
    if (eventIDPart == null) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.RequestEventValue_0_THE_EVENT_ID_FOR_THE_GET_EVENT_VALUE_REQUEST_IS_NULL, serverConnection.getName()));
        errMessage.append(" The event id for the get event value request is null.");
        writeErrorResponse(clientMessage, MessageType.REQUESTDATAERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    } else {
        try {
            event = (EventID) eventIDPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (parts > 1) {
            valuePart = clientMessage.getPart(1);
            try {
                if (valuePart != null) {
                    callbackArg = valuePart.getObject();
                }
            } catch (Exception e) {
                writeException(clientMessage, e, false, serverConnection);
                serverConnection.setAsTrue(RESPONDED);
                return;
            }
        }
        if (logger.isTraceEnabled()) {
            logger.trace("{}: Received get event value request ({} bytes) from {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString());
        }
        CacheClientNotifier ccn = serverConnection.getAcceptor().getCacheClientNotifier();
        // Get the ha container.
        HAContainerWrapper haContainer = (HAContainerWrapper) ccn.getHaContainer();
        if (haContainer == null) {
            String reason = " was not found during get event value request";
            writeRegionDestroyedEx(clientMessage, "ha container", reason, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } else {
            Object[] valueAndIsObject = new Object[2];
            try {
                Object data = haContainer.get(new HAEventWrapper(event));
                if (data == null) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.RequestEventValue_UNABLE_TO_FIND_A_CLIENT_UPDATE_MESSAGE_FOR_0, event));
                    String msgStr = "No value found for " + event + " in " + haContainer.getName();
                    writeErrorResponse(clientMessage, MessageType.REQUEST_EVENT_VALUE_ERROR, msgStr, serverConnection);
                    serverConnection.setAsTrue(RESPONDED);
                    return;
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Value retrieved for event {}", event);
                    }
                    Object val = ((ClientUpdateMessageImpl) data).getValueToConflate();
                    if (!(val instanceof byte[])) {
                        if (val instanceof CachedDeserializable) {
                            val = ((CachedDeserializable) val).getSerializedValue();
                        } else {
                            val = CacheServerHelper.serialize(val);
                        }
                        ((ClientUpdateMessageImpl) data).setLatestValue(val);
                    }
                    valueAndIsObject[0] = val;
                    valueAndIsObject[1] = Boolean.valueOf(((ClientUpdateMessageImpl) data).valueIsObject());
                }
            } catch (Exception e) {
                writeException(clientMessage, e, false, serverConnection);
                serverConnection.setAsTrue(RESPONDED);
                return;
            }
            Object data = valueAndIsObject[0];
            boolean isObject = (Boolean) valueAndIsObject[1];
            writeResponse(data, callbackArg, clientMessage, isObject, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            ccn.getClientProxy(serverConnection.getProxyID()).getStatistics().incDeltaFullMessagesSent();
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Wrote get event value response back to {} for ha container {}", serverConnection.getName(), serverConnection.getSocketString(), haContainer.getName());
            }
        }
    }
}
Also used : ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) HAContainerWrapper(org.apache.geode.internal.cache.ha.HAContainerWrapper) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) Part(org.apache.geode.internal.cache.tier.sockets.Part) EventID(org.apache.geode.internal.cache.EventID) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 7 with ClientUpdateMessageImpl

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl in project geode by apache.

the class Bug38741DUnitTest method testCopyOnReadWithBridgeServer.

/**
   * Test that CopyOnRead doesn't cause {@link HARegionQueue#peek()} to create a copy, assuming that
   * creating copies performs a serialize and de-serialize operation.
   * 
   * @throws Exception when there is a failure
   * @since GemFire bugfix5.7
   */
@Test
public void testCopyOnReadWithBridgeServer() throws Exception {
    final Host h = Host.getHost(0);
    final VM client = h.getVM(2);
    final VM server = h.getVM(3);
    final String rName = getUniqueName();
    final int[] ports = createUniquePorts(1);
    final String k1 = "k1";
    final String k2 = "k2";
    final String k3 = "k3";
    createBridgeServer(server, rName, ports[0]);
    // Put an instance of SerializationCounter to assert copy-on-read behavior
    // when notifyBySubscription is true
    server.invoke(new CacheSerializableRunnable("Enable copy on read and assert server copy behavior") {

        public void run2() throws CacheException {
            final LocalRegion r = (LocalRegion) getRootRegion(rName);
            // Using a key that counts serialization, the test captures
            // any serialization of the key when it is a member of another object,
            // specifically in this case ClientUpdateMessageImpl which is assume to be
            // the value of a HARegion
            SerializationCountingKey key = new SerializationCountingKey(k1);
            byte[] val = new byte[1];
            byte valIsObj = 0x01;
            Integer cb = new Integer(0);
            ClientProxyMembershipID cpmi = null;
            EventID eid = null;
            ClientUpdateMessageImpl cui = new ClientUpdateMessageImpl(EnumListenerEvent.AFTER_CREATE, r, key, val, valIsObj, cb, cpmi, eid);
            ClientUpdateMessageImpl cuiCopy = (ClientUpdateMessageImpl) CopyHelper.copy(cui);
            assertSame(key, cui.getKeyOfInterest());
            assertEquals(1, key.count.get());
            key = (SerializationCountingKey) cuiCopy.getKeyOfInterest();
            assertEquals(cui.getKeyOfInterest(), cuiCopy.getKeyOfInterest());
            assertEquals(1, key.count.get());
            SerializationCountingKey ks1 = new SerializationCountingKey(k1);
            {
                // Make sure nothing (HARegion) has serialized/de-serialized this instance
                SerializationCountingValue sc = new SerializationCountingValue();
                r.put(ks1, sc);
                assertEquals(0, sc.count.get());
                assertEquals(0, ks1.count.get());
            }
            {
                // No copy should be made upon get (assert standard no copy behavior)
                SerializationCountingValue sc = (SerializationCountingValue) r.get(ks1);
                assertEquals(0, sc.count.get());
                assertEquals(0, ks1.count.get());
            }
            // enable copy on read
            getCache().setCopyOnRead(true);
            {
                // Assert standard copy on read behavior
                SerializationCountingValue sc = (SerializationCountingValue) r.get(ks1);
                assertEquals(1, sc.count.get());
                assertEquals(0, ks1.count.get());
            }
            {
                // Put another counter with copy-on-read true
                // Again check that nothing (HARegion) has performed serialization
                SerializationCountingValue sc = new SerializationCountingValue();
                SerializationCountingKey ks3 = new SerializationCountingKey(k3);
                r.put(ks3, sc);
                assertEquals(0, sc.count.get());
                assertEquals(0, ks3.count.get());
            }
        }
    });
    // Setup a client which subscribes to the server region, registers (aka pulls)
    // interest in keys which creates an assumed HARegionQueue on the server
    // (in the event that the above code didn't already create a HARegion)
    final String serverHostName = NetworkUtils.getServerHostName(server.getHost());
    client.invoke(new CacheSerializableRunnable("Assert server copy behavior from client") {

        public void run2() throws CacheException {
            getCache();
            AttributesFactory factory = new AttributesFactory();
            ClientServerTestCase.configureConnectionPool(factory, serverHostName, ports, true, -1, 1, null);
            factory.setScope(Scope.LOCAL);
            Region r = createRootRegion(rName, factory.create());
            SerializationCountingKey ks1 = new SerializationCountingKey(k1);
            SerializationCountingKey ks3 = new SerializationCountingKey(k3);
            r.registerInterest(ks1, InterestResultPolicy.KEYS_VALUES);
            // entry
            r.registerInterest(new SerializationCountingKey(k2), InterestResultPolicy.KEYS_VALUES);
            // shouldn't
            // exist
            // yet
            r.registerInterest(ks3, InterestResultPolicy.KEYS_VALUES);
            {
                // Once for the get on the server, once to send the value to this client
                SerializationCountingValue sc = (SerializationCountingValue) r.get(ks1);
                assertEquals(2, sc.count.get());
            }
            {
                // Once to send the value to this client
                SerializationCountingValue sc = (SerializationCountingValue) r.get(ks3);
                assertEquals(1, sc.count.get());
            }
        }
    });
    // Put an instance of SerializationCounter to assert copy-on-read behavior
    // once a client has registered interest
    server.invoke(new CacheSerializableRunnable("Assert copy behavior after client is setup") {

        public void run2() throws CacheException {
            Region r = getRootRegion(rName);
            CacheServerImpl bsi = (CacheServerImpl) getCache().getCacheServers().iterator().next();
            Collection cp = bsi.getAcceptor().getCacheClientNotifier().getClientProxies();
            // Should only be one because only one client is connected
            assertEquals(1, cp.size());
            final CacheClientProxy ccp = (CacheClientProxy) cp.iterator().next();
            // Wait for messages to drain to capture a stable "processed message count"
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return ccp.getHARegionQueue().size() == 0;
                }

                public String description() {
                    return "region queue never became empty";
                }
            };
            Wait.waitForCriterion(ev, 60 * 1000, 200, true);
            // Capture the current processed message count to know
            // when the next message has been serialized
            final int currMesgCount = ccp.getStatistics().getMessagesProcessed();
            SerializationCountingKey ks2 = new SerializationCountingKey(k2);
            SerializationCountingValue sc = new SerializationCountingValue();
            // Update a key upon which the client has expressed interest,
            // expect it to send an update message to the client
            r.put(ks2, sc);
            // Wait to know that the data has been at least serialized (possibly sent)
            ev = new WaitCriterion() {

                public boolean done() {
                    return ccp.getStatistics().getMessagesProcessed() != currMesgCount;
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, 60 * 1000, 200, true);
            // assert one serialization to send value to interested client
            // more than one implies copy-on-read behavior (bad)
            assertEquals(1, sc.count.get());
            assertEquals(1, ks2.count.get());
        }
    });
    // Double-check the serialization count in the event that the previous check
    // missed the copy due to race conditions
    client.invoke(new CacheSerializableRunnable("Assert copy behavior from client after update") {

        public void run2() throws CacheException {
            Region r = getRootRegion(rName);
            {
                // Once to send the value to this client via the updater thread
                SerializationCountingKey ks2 = new SerializationCountingKey(k2);
                // Wait for the update to arrive on to the Cache Client Updater
                long start = NanoTimer.getTime();
                final int maxSecs = 30;
                while (!r.containsKey(ks2)) {
                    Wait.pause(100);
                    if ((NanoTimer.getTime() - start) > TimeUnit.SECONDS.toNanos(maxSecs)) {
                        fail("Waited over " + maxSecs + "s");
                    }
                }
                SerializationCountingValue sc = (SerializationCountingValue) r.getEntry(ks2).getValue();
                assertEquals(1, sc.count.get());
            }
        }
    });
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Collection(java.util.Collection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with ClientUpdateMessageImpl

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl in project geode by apache.

the class AbstractRegionMap method initialImagePut.

public boolean initialImagePut(final Object key, final long lastModified, Object newValue, final boolean wasRecovered, boolean deferLRUCallback, VersionTag entryVersion, InternalDistributedMember sender, boolean isSynchronizing) {
    boolean result = false;
    boolean done = false;
    boolean cleared = false;
    final LocalRegion owner = _getOwner();
    if (newValue == Token.TOMBSTONE && !owner.getConcurrencyChecksEnabled()) {
        return false;
    }
    if (owner instanceof HARegion && newValue instanceof CachedDeserializable) {
        Object actualVal = ((CachedDeserializable) newValue).getDeserializedValue(null, null);
        if (actualVal instanceof HAEventWrapper) {
            HAEventWrapper haEventWrapper = (HAEventWrapper) actualVal;
            // Key was removed at sender side so not putting it into the HARegion
            if (haEventWrapper.getClientUpdateMessage() == null) {
                return false;
            }
            // Getting the instance from singleton CCN..This assumes only one bridge
            // server in the VM
            HAContainerWrapper haContainer = (HAContainerWrapper) CacheClientNotifier.getInstance().getHaContainer();
            if (haContainer == null) {
                return false;
            }
            HAEventWrapper original = null;
            // synchronized (haContainer) {
            do {
                ClientUpdateMessageImpl oldMsg = (ClientUpdateMessageImpl) haContainer.putIfAbsent(haEventWrapper, haEventWrapper.getClientUpdateMessage());
                if (oldMsg != null) {
                    original = (HAEventWrapper) haContainer.getKey(haEventWrapper);
                    if (original == null) {
                        continue;
                    }
                    synchronized (original) {
                        if ((HAEventWrapper) haContainer.getKey(original) != null) {
                            original.incAndGetReferenceCount();
                            HARegionQueue.addClientCQsAndInterestList(oldMsg, haEventWrapper, haContainer, owner.getName());
                            haEventWrapper.setClientUpdateMessage(null);
                            newValue = CachedDeserializableFactory.create(original, ((CachedDeserializable) newValue).getSizeInBytes());
                        } else {
                            original = null;
                        }
                    }
                } else {
                    // putIfAbsent successful
                    synchronized (haEventWrapper) {
                        haEventWrapper.incAndGetReferenceCount();
                        haEventWrapper.setHAContainer(haContainer);
                        haEventWrapper.setClientUpdateMessage(null);
                        haEventWrapper.setIsRefFromHAContainer(true);
                    }
                    break;
                }
            // try until we either get a reference to HAEventWrapper from
            // HAContainer or successfully put one into it.
            } while (original == null);
        /*
         * entry = (Map.Entry)haContainer.getEntry(haEventWrapper); if (entry != null) { original =
         * (HAEventWrapper)entry.getKey(); original.incAndGetReferenceCount(); } else {
         * haEventWrapper.incAndGetReferenceCount(); haEventWrapper.setHAContainer(haContainer);
         * haContainer.put(haEventWrapper, haEventWrapper .getClientUpdateMessage());
         * haEventWrapper.setClientUpdateMessage(null);
         * haEventWrapper.setIsRefFromHAContainer(true); } } if (entry != null) {
         * HARegionQueue.addClientCQsAndInterestList(entry, haEventWrapper, haContainer,
         * owner.getName()); haEventWrapper.setClientUpdateMessage(null); newValue =
         * CachedDeserializableFactory.create(original,
         * ((CachedDeserializable)newValue).getSizeInBytes()); }
         */
        }
    }
    try {
        RegionEntry newRe = getEntryFactory().createEntry(owner, key, Token.REMOVED_PHASE1);
        EntryEventImpl event = null;
        @Retained @Released Object oldValue = null;
        try {
            RegionEntry oldRe = null;
            synchronized (newRe) {
                try {
                    oldRe = putEntryIfAbsent(key, newRe);
                    while (!done && oldRe != null) {
                        synchronized (oldRe) {
                            if (oldRe.isRemovedPhase2()) {
                                owner.getCachePerfStats().incRetries();
                                _getMap().remove(key, oldRe);
                                oldRe = putEntryIfAbsent(key, newRe);
                            } else {
                                boolean acceptedVersionTag = false;
                                if (entryVersion != null && owner.concurrencyChecksEnabled) {
                                    Assert.assertTrue(entryVersion.getMemberID() != null, "GII entry versions must have identifiers");
                                    try {
                                        boolean isTombstone = (newValue == Token.TOMBSTONE);
                                        // don't reschedule the tombstone if it hasn't changed
                                        boolean isSameTombstone = oldRe.isTombstone() && isTombstone && oldRe.getVersionStamp().asVersionTag().equals(entryVersion);
                                        if (isSameTombstone) {
                                            return true;
                                        }
                                        processVersionTagForGII(oldRe, owner, entryVersion, isTombstone, sender, !wasRecovered || isSynchronizing);
                                        acceptedVersionTag = true;
                                    } catch (ConcurrentCacheModificationException e) {
                                        return false;
                                    }
                                }
                                final boolean oldIsTombstone = oldRe.isTombstone();
                                final int oldSize = owner.calculateRegionEntryValueSize(oldRe);
                                try {
                                    result = oldRe.initialImagePut(owner, lastModified, newValue, wasRecovered, acceptedVersionTag);
                                    if (result) {
                                        if (oldIsTombstone) {
                                            owner.unscheduleTombstone(oldRe);
                                            if (newValue != Token.TOMBSTONE) {
                                                lruEntryCreate(oldRe);
                                            } else {
                                                lruEntryUpdate(oldRe);
                                            }
                                        }
                                        if (newValue == Token.TOMBSTONE) {
                                            owner.updateSizeOnRemove(key, oldSize);
                                            if (owner.getServerProxy() == null && owner.getVersionVector().isTombstoneTooOld(entryVersion.getMemberID(), entryVersion.getRegionVersion())) {
                                                // the received tombstone has already been reaped, so don't retain it
                                                removeTombstone(oldRe, entryVersion, false, false);
                                                return false;
                                            } else {
                                                owner.scheduleTombstone(oldRe, entryVersion);
                                                lruEntryDestroy(oldRe);
                                            }
                                        } else {
                                            int newSize = owner.calculateRegionEntryValueSize(oldRe);
                                            if (!oldIsTombstone) {
                                                owner.updateSizeOnPut(key, oldSize, newSize);
                                            } else {
                                                owner.updateSizeOnCreate(key, newSize);
                                            }
                                            EntryLogger.logInitialImagePut(_getOwnerObject(), key, newValue);
                                        }
                                    }
                                    if (owner.getIndexManager() != null) {
                                        // as the update could not locate the old key
                                        if (!oldRe.isRemoved()) {
                                            owner.getIndexManager().updateIndexes(oldRe, IndexManager.REMOVE_ENTRY, IndexProtocol.BEFORE_UPDATE_OP);
                                        }
                                        owner.getIndexManager().updateIndexes(oldRe, oldRe.isRemoved() ? IndexManager.ADD_ENTRY : IndexManager.UPDATE_ENTRY, oldRe.isRemoved() ? IndexProtocol.OTHER_OP : IndexProtocol.AFTER_UPDATE_OP);
                                    }
                                    done = true;
                                } finally {
                                    if (event != null) {
                                        event.release();
                                        event = null;
                                    }
                                }
                            }
                        }
                    }
                    if (!done) {
                        boolean versionTagAccepted = false;
                        if (entryVersion != null && owner.concurrencyChecksEnabled) {
                            Assert.assertTrue(entryVersion.getMemberID() != null, "GII entry versions must have identifiers");
                            try {
                                boolean isTombstone = (newValue == Token.TOMBSTONE);
                                processVersionTagForGII(newRe, owner, entryVersion, isTombstone, sender, !wasRecovered || isSynchronizing);
                                versionTagAccepted = true;
                            } catch (ConcurrentCacheModificationException e) {
                                return false;
                            }
                        }
                        result = newRe.initialImageInit(owner, lastModified, newValue, true, wasRecovered, versionTagAccepted);
                        try {
                            if (result) {
                                if (newValue == Token.TOMBSTONE) {
                                    owner.scheduleTombstone(newRe, entryVersion);
                                } else {
                                    owner.updateSizeOnCreate(key, owner.calculateRegionEntryValueSize(newRe));
                                    EntryLogger.logInitialImagePut(_getOwnerObject(), key, newValue);
                                    lruEntryCreate(newRe);
                                }
                                incEntryCount(1);
                            }
                            // Update local indexes
                            if (owner.getIndexManager() != null) {
                                // the update could not locate the old key
                                if (oldRe != null && !oldRe.isRemoved()) {
                                    owner.getIndexManager().updateIndexes(oldRe, IndexManager.REMOVE_ENTRY, IndexProtocol.BEFORE_UPDATE_OP);
                                }
                                owner.getIndexManager().updateIndexes(newRe, newRe.isRemoved() ? IndexManager.REMOVE_ENTRY : IndexManager.UPDATE_ENTRY, newRe.isRemoved() ? IndexProtocol.OTHER_OP : IndexProtocol.AFTER_UPDATE_OP);
                            }
                            done = true;
                        } finally {
                            if (event != null) {
                                event.release();
                                event = null;
                            }
                        }
                    }
                } finally {
                    if (done && result) {
                        initialImagePutEntry(newRe);
                    }
                    if (!done) {
                        removeEntry(key, newRe, false);
                        if (owner.getIndexManager() != null) {
                            owner.getIndexManager().updateIndexes(newRe, IndexManager.REMOVE_ENTRY, IndexProtocol.OTHER_OP);
                        }
                    }
                }
            }
        // synchronized
        } finally {
            if (event != null)
                event.release();
            OffHeapHelper.release(oldValue);
        }
    } catch (RegionClearedException rce) {
        // Asif: do not issue any sort of callbacks
        done = false;
        cleared = true;
    } catch (QueryException qe) {
        done = false;
        cleared = true;
    } finally {
        if (done && !deferLRUCallback) {
            lruUpdateCallback();
        } else if (!cleared) {
            resetThreadLocals();
        }
    }
    return result;
}
Also used : ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) HAContainerWrapper(org.apache.geode.internal.cache.ha.HAContainerWrapper) Released(org.apache.geode.internal.offheap.annotations.Released) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) QueryException(org.apache.geode.cache.query.QueryException) Retained(org.apache.geode.internal.offheap.annotations.Retained) StoredObject(org.apache.geode.internal.offheap.StoredObject) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 9 with ClientUpdateMessageImpl

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl in project geode by apache.

the class HAOverflowMemObjectSizerDUnitTest method sizerTestForMemCapacityController.

/**
   * Check for size return by ClientUpdateMessagesImpl getSizeInByte() with size return by
   * memCapacity controller
   *
   * @param port - BridgeServer port required to get ClientMessagesRegion
   */
public static void sizerTestForMemCapacityController(Integer port) {
    region = cache.getRegion(Region.SEPARATOR + CacheServerImpl.generateNameForClientMsgsRegion(port.intValue()));
    assertNotNull(region);
    Set entries = region.entrySet();
    assertTrue(entries.size() > 0);
    Iterator iter = entries.iterator();
    for (; iter.hasNext(); ) {
        Region.Entry entry = (Region.Entry) iter.next();
        ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl) entry.getValue();
        // passed null to get the size of value ie CUM only ,
        // but this function also add overhead per entry
        // so to get exact size calculated by memCapacityController
        // we need substract this over head
        // as this default value is private static in MemLRUCapacityController
        // cannot access directly
        assertTrue("cum size is not equal", (cc.entrySize(null, entry.getValue()) - OVERHEAD_PER_ENTRY) == cum.getSizeInBytes());
    }
    cache.getLogger().fine("Test passed. Now, doing a cleanup job.");
    // added here as sleep should be on server where CMR is present and
    // dispacher supposed to run
    cleanUp(new Long(20000));
}
Also used : ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) Set(java.util.Set) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Aggregations

ClientUpdateMessageImpl (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl)9 HAEventWrapper (org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)4 Region (org.apache.geode.cache.Region)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 CacheException (org.apache.geode.cache.CacheException)2 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)2 EventID (org.apache.geode.internal.cache.EventID)2 HAContainerWrapper (org.apache.geode.internal.cache.ha.HAContainerWrapper)2 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 QueryException (org.apache.geode.cache.query.QueryException)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1