Search in sources :

Example 21 with ClientProxyMembershipID

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

the class Request method getValueAndIsObject.

// take the result 2 element "result" as argument instead of
// returning as the result to avoid creating the array repeatedly
// for large number of entries like in getAll
public void getValueAndIsObject(Region region, Object key, Object callbackArg, ServerConnection servConn, Object[] result) {
    String regionName = region.getFullPath();
    if (servConn != null) {
        servConn.setModificationInfo(true, regionName, key);
    }
    boolean isObject = true;
    ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
    Object data = ((LocalRegion) region).get(key, callbackArg, true, true, true, id, null, false);
    // disk. If it is already a byte[], set isObject to false.
    if (data instanceof CachedDeserializable) {
        CachedDeserializable cd = (CachedDeserializable) data;
        if (!cd.isSerialized()) {
            // it is a byte[]
            isObject = false;
            data = cd.getDeserializedForReading();
        } else {
            data = cd.getValue();
        }
    } else if (data == Token.REMOVED_PHASE1 || data == Token.REMOVED_PHASE2 || data == Token.TOMBSTONE || data == Token.DESTROYED) {
        data = null;
    } else if (data == Token.INVALID || data == Token.LOCAL_INVALID) {
        // fix for bug 35884
        data = null;
    } else if (data instanceof byte[]) {
        isObject = false;
    }
    result[0] = data;
    result[1] = Boolean.valueOf(isObject);
    result[2] = (data == null);
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 22 with ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID 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 23 with ClientProxyMembershipID

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

the class GemFireMemberStatus method getClientIDMap.

/**
   * returning Map of client queue size against client Id
   * 
   * param clientMap is a Map of client queue size against ClientProxyMembershipID
   */
private Map getClientIDMap(Map ClientProxyMembershipIDMap) {
    Map clientIdMap = new HashMap();
    Set entrySet = ClientProxyMembershipIDMap.entrySet();
    Iterator entries = entrySet.iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        ClientProxyMembershipID key = (ClientProxyMembershipID) entry.getKey();
        Integer size = (Integer) entry.getValue();
        clientIdMap.put(key.getDSMembership(), size);
    }
    return clientIdMap;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with ClientProxyMembershipID

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

the class ClientCacheFactoryJUnitTest method testOldClientIDDeserialization.

@Test
public void testOldClientIDDeserialization() throws Exception {
    // during a HandShake a clientID is read w/o knowing the client's
    // version
    cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) cc;
    InternalDistributedMember memberID = (InternalDistributedMember) cc.getDistributedSystem().getDistributedMember();
    GMSMember gmsID = (GMSMember) memberID.getNetMember();
    memberID.setVersionObjectForTest(Version.GFE_82);
    assertEquals(Version.GFE_82, memberID.getVersionObject());
    ClientProxyMembershipID clientID = ClientProxyMembershipID.getClientId(memberID);
    HeapDataOutputStream out = new HeapDataOutputStream(Version.GFE_82);
    DataSerializer.writeObject(clientID, out);
    DataInputStream in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
    ClientProxyMembershipID newID = DataSerializer.readObject(in);
    InternalDistributedMember newMemberID = (InternalDistributedMember) newID.getDistributedMember();
    assertEquals(Version.GFE_82, newMemberID.getVersionObject());
    assertEquals(Version.GFE_82, newID.getClientVersion());
    GMSMember newGmsID = (GMSMember) newMemberID.getNetMember();
    assertEquals(0, newGmsID.getUuidLSBs());
    assertEquals(0, newGmsID.getUuidMSBs());
    gmsID.setUUID(new UUID(1234l, 5678l));
    memberID.setVersionObjectForTest(Version.CURRENT);
    clientID = ClientProxyMembershipID.getClientId(memberID);
    out = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeObject(clientID, out);
    in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
    newID = DataSerializer.readObject(in);
    newMemberID = (InternalDistributedMember) newID.getDistributedMember();
    assertEquals(Version.CURRENT, newMemberID.getVersionObject());
    assertEquals(Version.CURRENT, newID.getClientVersion());
    newGmsID = (GMSMember) newMemberID.getNetMember();
    assertEquals(gmsID.getUuidLSBs(), newGmsID.getUuidLSBs());
    assertEquals(gmsID.getUuidMSBs(), newGmsID.getUuidMSBs());
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) UUID(org.jgroups.util.UUID) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with ClientProxyMembershipID

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

the class DataSerializerTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    DataSerializer mockDataSerializer = mock(DataSerializer.class);
    EventID mockEventID = mock(EventID.class);
    ClientProxyMembershipID mockClientProxyMembershipID = mock(ClientProxyMembershipID.class);
    when(mockDataSerializer.getEventId()).thenReturn(mockEventID);
    when(mockDataSerializer.getContext()).thenReturn(mockClientProxyMembershipID);
    mockDataSerializer.setEventId(mockEventID);
    mockDataSerializer.setContext(mockClientProxyMembershipID);
    verify(mockDataSerializer, times(1)).setEventId(mockEventID);
    verify(mockDataSerializer, times(1)).setContext(mockClientProxyMembershipID);
    assertThat(mockDataSerializer.getEventId()).isSameAs(mockEventID);
    assertThat(mockDataSerializer.getContext()).isSameAs(mockClientProxyMembershipID);
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) EventID(org.apache.geode.internal.cache.EventID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)30 Test (org.junit.Test)10 IOException (java.io.IOException)7 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)7 CqException (org.apache.geode.cache.query.CqException)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CqService (org.apache.geode.cache.query.internal.cq.CqService)5 EventID (org.apache.geode.internal.cache.EventID)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Iterator (java.util.Iterator)4 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)4 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 HashSet (java.util.HashSet)3 CacheException (org.apache.geode.cache.CacheException)3 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)3