Search in sources :

Example 1 with DeltaTestImpl

use of org.apache.geode.DeltaTestImpl in project geode by apache.

the class PRDeltaPropagationDUnitTest method createClientCache.

public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
    PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    test.createCache(props);
    lastKeyReceived = false;
    queryUpdateExecuted = false;
    queryDestroyExecuted = false;
    notADeltaInstanceObj = false;
    isFailed = false;
    procced = false;
    numValidCqEvents = 0;
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setConcurrencyChecksEnabled(true);
    if (isEmpty.booleanValue()) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        factory.setDataPolicy(DataPolicy.EMPTY);
    }
    factory.setPoolName(p.getName());
    factory.setCloningEnabled(false);
    factory.addCacheListener(new CacheListenerAdapter() {

        @Override
        public void afterCreate(EntryEvent event) {
            if (LAST_KEY.equals(event.getKey())) {
                lastKeyReceived = true;
            }
        }
    });
    RegionAttributes attrs = factory.create();
    deltaPR = cache.createRegion(REGION_NAME, attrs);
    if (subscriptionEnable.booleanValue()) {
        deltaPR.registerInterest("ALL_KEYS");
    }
    pool = p;
    if (isCq.booleanValue()) {
        CqAttributesFactory cqf = new CqAttributesFactory();
        CqListenerAdapter cqlist = new CqListenerAdapter() {

            @Override
            @SuppressWarnings("synthetic-access")
            public void onEvent(CqEvent cqEvent) {
                if (LAST_KEY.equals(cqEvent.getKey().toString())) {
                    lastKeyReceived = true;
                } else if (!(cqEvent.getNewValue() instanceof Delta)) {
                    notADeltaInstanceObj = true;
                } else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
                    queryUpdateExecuted = true;
                } else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
                    queryDestroyExecuted = true;
                }
                if (forOldNewCQVarification) {
                    if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
                        if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
                            procced = true;
                        } else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
                            // this tell us that every thing is fine
                            isFailed = true;
                        }
                    }
                }
                numValidCqEvents++;
            }
        };
        cqf.addCqListener(cqlist);
        CqAttributes cqa = cqf.create();
        CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
        cq.execute();
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) DeltaTestImpl(org.apache.geode.DeltaTestImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CqEvent(org.apache.geode.cache.query.CqEvent) Delta(org.apache.geode.Delta) CqAttributes(org.apache.geode.cache.query.CqAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 2 with DeltaTestImpl

use of org.apache.geode.DeltaTestImpl in project geode by apache.

the class PRDeltaPropagationDUnitTest method testDeltaPropagationPRAccessorAsBridgeServerWithDeltaException.

/**
   * 1) Put delta objects on client feeder connected PR accessor bridge server. 2) From accessor to
   * data store delta gets propagated as part of <code>PutMessage</code> delta. 3) Exception occurs
   * when applying delta on datastore node. This invalid delta exception propagated back to client
   * through accessor. 4) Client sends full object in response.
   */
@Test
public void testDeltaPropagationPRAccessorAsBridgeServerWithDeltaException() throws Exception {
    Object[] args1 = new Object[] { REGION_NAME, new Integer(0), new Integer(0), new Integer(8), Boolean.FALSE, null };
    Object[] args2 = new Object[] { REGION_NAME, new Integer(0), new Integer(50), new Integer(8), Boolean.FALSE, null };
    Integer port2 = (Integer) dataStore2.invoke(PRDeltaPropagationDUnitTest.class, "createCacheServerWithPR", args2);
    Integer port1 = (Integer) dataStore1.invoke(PRDeltaPropagationDUnitTest.class, "createCacheServerWithPR", args1);
    createClientCache(port1, new Boolean(false), new Boolean(false), new Boolean(false));
    client1.invoke(() -> PRDeltaPropagationDUnitTest.createClientCache(port2, new Boolean(true), new Boolean(false), new Boolean(false)));
    // feed delta
    DeltaTestImpl test = new DeltaTestImpl();
    deltaPR.put(DELTA_KEY, test);
    test.setIntVar(10);
    deltaPR.put(DELTA_KEY, test);
    // perform invalidate on accessor
    dataStore2.invoke(() -> PRDeltaPropagationDUnitTest.invalidateDeltaKey());
    test = new DeltaTestImpl();
    test.setStr("DELTA");
    deltaPR.put(DELTA_KEY, test);
    deltaPR.put(LAST_KEY, "");
    client1.invoke(() -> PRDeltaPropagationDUnitTest.waitForLastKey());
    client1.invoke(() -> PRDeltaPropagationDUnitTest.checkForFullObject());
}
Also used : DeltaTestImpl(org.apache.geode.DeltaTestImpl) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

Example 3 with DeltaTestImpl

use of org.apache.geode.DeltaTestImpl in project geode by apache.

the class PRDeltaPropagationDUnitTest method testCQRIClientOnRedundantBucketReceivesDeltaAndCQEvents.

/**
   * Toplogy: PR: Accessor,DataStore,Bridge server; configured for 2 buckets and redundancy 1
   * DataStore has primary while BridgeServer has secondary of bucket. client connects to PR
   * Accessor client1 connects to PR BridgeServer client1 registers Interest as well as CQ client
   * puts delta objects on accessor Verify that client1 receives 2 deltas for 2 updates (due to RI)
   * Verify on client1 that queryUpdate and queryDestroy are executed properly
   */
@Test
public void testCQRIClientOnRedundantBucketReceivesDeltaAndCQEvents() throws Exception {
    // args for accessor
    Object[] args1 = new Object[] { REGION_NAME, new Integer(1), new Integer(0), new Integer(2), Boolean.FALSE, null };
    // args for dataStore with 2 buckets
    Object[] args2 = new Object[] { REGION_NAME, new Integer(1), new Integer(50), new Integer(2), Boolean.FALSE, null };
    // dataStore2 is DataStore
    // implicit put of DELTA_KEY creates primary bucket on dataStore2
    dataStore2.invoke(PRDeltaPropagationDUnitTest.class, "createCacheServerWithPR", args2);
    // dataStore3 is BridgeServer
    // this has secondary bucket
    Integer port3 = (Integer) dataStore3.invoke(PRDeltaPropagationDUnitTest.class, "createCacheServerWithPR", args2);
    // dataStore1 is accessor
    Integer port1 = (Integer) dataStore1.invoke(PRDeltaPropagationDUnitTest.class, "createCacheServerWithPR", args1);
    // this client is attached to accessor - (port1)
    createClientCache(port1, new Boolean(false), new Boolean(true), new Boolean(false));
    // client1 is attached to BridgeServer dataStore3
    // client1 registers Interest as well as cq
    client1.invoke(() -> PRDeltaPropagationDUnitTest.createClientCache(port3, new Boolean(true), new Boolean(false), new Boolean(true)));
    // create delta keys (1 primary 1 redundant bucket on each dataStore)
    DeltaTestImpl test = new DeltaTestImpl(8, "");
    deltaPR.put(DELTA_KEY, test);
    test.setIntVar(10);
    deltaPR.put(DELTA_KEY, test);
    deltaPR.put(LAST_KEY, new DeltaTestImpl(8, ""));
    client1.invoke(() -> PRDeltaPropagationDUnitTest.waitForLastKey());
    client1.invoke(() -> PRDeltaPropagationDUnitTest.fromDeltaCounter(new Integer(1)));
    boolean flag = ((Boolean) client1.invoke(() -> PRDeltaPropagationDUnitTest.verifyQueryUpdateExecuted())).booleanValue();
    assertTrue("client update cq not executed properly", flag);
    flag = ((Boolean) client1.invoke(() -> PRDeltaPropagationDUnitTest.verifyQueryDestroyExecuted())).booleanValue();
    assertTrue("client destroy cq not executed properly", flag);
}
Also used : DeltaTestImpl(org.apache.geode.DeltaTestImpl) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

Example 4 with DeltaTestImpl

use of org.apache.geode.DeltaTestImpl in project geode by apache.

the class DeltaClientPostAuthorizationDUnitTest method setUpDeltas.

private void setUpDeltas() {
    for (int i = 0; i < 8; i++) {
        deltas[i] = new DeltaTestImpl(0, "0", new Double(0), new byte[0], new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("0", 0));
    }
    deltas[1].setIntVar(5);
    deltas[2].setIntVar(5);
    deltas[3].setIntVar(5);
    deltas[4].setIntVar(5);
    deltas[5].setIntVar(5);
    deltas[6].setIntVar(5);
    deltas[7].setIntVar(5);
    deltas[2].resetDeltaStatus();
    deltas[2].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    deltas[3].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    deltas[4].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    deltas[5].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    // deltas[6].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    // deltas[7].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
    deltas[3].resetDeltaStatus();
    deltas[3].setDoubleVar(new Double(5));
    deltas[4].setDoubleVar(new Double(5));
    deltas[5].setDoubleVar(new Double(5));
    deltas[6].setDoubleVar(new Double(5));
    deltas[7].setDoubleVar(new Double(5));
    deltas[4].resetDeltaStatus();
    deltas[4].setStr("str changed");
    deltas[5].setStr("str changed");
    deltas[6].setStr("str changed");
    // deltas[7].setStr("str changed");
    deltas[5].resetDeltaStatus();
    deltas[5].setIntVar(100);
    deltas[5].setTestObj(new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("CHANGED", 100));
    deltas[6].setTestObj(new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("CHANGED", 100));
    deltas[7].setTestObj(new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("CHANGED", 100));
    deltas[6].resetDeltaStatus();
    deltas[6].setByteArr(new byte[] { 1, 2, 3 });
    deltas[7].setByteArr(new byte[] { 1, 2, 3 });
    deltas[7].resetDeltaStatus();
    deltas[7].setStr("delta string");
}
Also used : DeltaTestImpl(org.apache.geode.DeltaTestImpl) PartitionedRegionLocalMaxMemoryDUnitTest(org.apache.geode.internal.cache.PartitionedRegionLocalMaxMemoryDUnitTest)

Example 5 with DeltaTestImpl

use of org.apache.geode.DeltaTestImpl in project geode by apache.

the class ClientToServerDeltaDUnitTest method putDelta.

/*
   * put delta ; not previous deltas
   */
private static void putDelta(String key) {
    Region r = cache.getRegion(REGION_NAME);
    DeltaTestImpl val = null;
    for (int i = 0; i < NO_PUT_OPERATION; i++) {
        val = new DeltaTestImpl(0, "0", new Double(0), new byte[0], new TestObject1("0", 0));
        switch(i) {
            case 1:
                val.setStr((String) putDelta[0]);
                break;
            case 2:
                val.setIntVar(((Integer) putDelta[2]).intValue());
                break;
        }
        r.put(key, val);
    }
}
Also used : DeltaTestImpl(org.apache.geode.DeltaTestImpl) TestObject1(org.apache.geode.internal.cache.PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region)

Aggregations

DeltaTestImpl (org.apache.geode.DeltaTestImpl)38 Region (org.apache.geode.cache.Region)21 Test (org.junit.Test)10 TestObject1 (org.apache.geode.internal.cache.PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)9 ConflationDUnitTest (org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest)8 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)8 LocalRegion (org.apache.geode.internal.cache.LocalRegion)7 InvalidDeltaException (org.apache.geode.InvalidDeltaException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 Properties (java.util.Properties)1 DataSerializable (org.apache.geode.DataSerializable)1 Delta (org.apache.geode.Delta)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 EntryEvent (org.apache.geode.cache.EntryEvent)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1