Search in sources :

Example 6 with EntrySnapshot

use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method testConflictChecksBasedOnDsidAndTimeStamp.

/**
   * Tests if conflict checks are happening based on DSID and timestamp even if version tag is
   * generated in local distributed system.
   */
@Test
public void testConflictChecksBasedOnDsidAndTimeStamp() {
    // create two distributed systems with each having a cache containing
    // a Replicated Region with one entry and concurrency checks enabled.
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    createCacheInVMs(lnPort, vm1);
    Integer lnRecPort = (Integer) vm1.invoke(() -> WANTestBase.createReceiver());
    // Site 2
    Integer nyPort = (Integer) vm2.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    createCacheInVMs(nyPort, vm3);
    Integer nyRecPort = (Integer) vm3.invoke(() -> WANTestBase.createReceiver());
    LogWriterUtils.getLogWriter().info("Created locators and receivers in 2 distributed systems");
    // Site 1
    vm1.invoke(() -> WANTestBase.createSender("ln1", 2, false, 10, 1, false, false, null, true));
    vm1.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ln1", isOffHeap()));
    vm1.invoke(() -> WANTestBase.startSender("ln1"));
    vm1.invoke(() -> WANTestBase.waitForSenderRunningState("ln1"));
    // Site 2
    vm3.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
    vm4.invoke(() -> WANTestBase.createCache(nyPort));
    vm4.invoke(() -> WANTestBase.createSender("ny1", 1, false, 10, 1, false, false, null, true));
    vm4.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
    vm4.invoke(() -> WANTestBase.startSender("ny1"));
    vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ny1"));
    Wait.pause(2000);
    // Perform a put in vm1
    vm1.invoke(new CacheSerializableRunnable("Putting an entry in ds1") {

        @Override
        public void run2() throws CacheException {
            assertNotNull(cache);
            Region region = cache.getRegion("/repRegion");
            region.put("testKey", "testValue1");
            assertEquals(1, region.size());
        }
    });
    // wait for vm4 to have later timestamp before sending operation to vm1
    Wait.pause(300);
    AsyncInvocation asynch = vm4.invokeAsync(new CacheSerializableRunnable("Putting an entry in ds2 in vm4") {

        @Override
        public void run2() throws CacheException {
            assertNotNull(cache);
            Region region = cache.getRegion("/repRegion");
            region.put("testKey", "testValue2");
            assertEquals(1, region.size());
            assertEquals("testValue2", region.get("testKey"));
        }
    });
    try {
        asynch.join(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Wait for all local ds events be received by vm3.
    Wait.pause(1000);
    vm3.invoke(new CacheSerializableRunnable("Check dsid") {

        @Override
        public void run2() throws CacheException {
            Region region = cache.getRegion("repRegion");
            Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
            true);
            // commented while merging revision 43582
            RegionEntry re = null;
            if (entry instanceof EntrySnapshot) {
                re = ((EntrySnapshot) entry).getRegionEntry();
            } else if (entry instanceof NonTXEntry) {
                re = ((NonTXEntry) entry).getRegionEntry();
            }
            VersionTag tag = re.getVersionStamp().asVersionTag();
            assertEquals(2, tag.getDistributedSystemId());
        }
    });
    // Check vm3 has latest timestamp from vm4.
    long putAllTimeStampVm1 = (Long) vm4.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
    long putAllTimeStampVm3 = (Long) vm3.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
    assertEquals(putAllTimeStampVm1, putAllTimeStampVm3);
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) CacheException(org.apache.geode.cache.CacheException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with EntrySnapshot

use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method verifyTimestampAfterOp.

/*
   * For VM 5 in ds 3.
   */
public static void verifyTimestampAfterOp(long timestamp, int memberid) {
    Region region = cache.getRegion("repRegion");
    assertEquals(0, region.size());
    Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
    true);
    RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
    assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
    VersionTag tag = re.getVersionStamp().asVersionTag();
    assertEquals(timestamp, tag.getVersionTimeStamp());
    assertEquals(memberid, tag.getDistributedSystemId());
}
Also used : Tombstone(org.apache.geode.internal.cache.Token.Tombstone) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 8 with EntrySnapshot

use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.

the class LuceneEventListener method getValue.

private Object getValue(Region.Entry entry) {
    final EntrySnapshot es = (EntrySnapshot) entry;
    Object value;
    try {
        value = es == null ? null : es.getRawValue(true);
    } catch (EntryDestroyedException e) {
        value = null;
    }
    return value;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 9 with EntrySnapshot

use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.

the class LuceneEventListenerJUnitTest method testProcessBatch.

@Test
public void testProcessBatch() throws Exception {
    RepositoryManager manager = Mockito.mock(RepositoryManager.class);
    IndexRepository repo1 = Mockito.mock(IndexRepository.class);
    IndexRepository repo2 = Mockito.mock(IndexRepository.class);
    Region region1 = Mockito.mock(Region.class);
    Region region2 = Mockito.mock(Region.class);
    Object callback1 = new Object();
    Mockito.when(manager.getRepository(eq(region1), any(), eq(callback1))).thenReturn(repo1);
    Mockito.when(manager.getRepository(eq(region2), any(), eq(null))).thenReturn(repo2);
    LuceneEventListener listener = new LuceneEventListener(manager);
    List<AsyncEvent> events = new ArrayList<AsyncEvent>();
    int numEntries = 100;
    for (int i = 0; i < numEntries; i++) {
        AsyncEvent event = Mockito.mock(AsyncEvent.class);
        Region region = i % 2 == 0 ? region1 : region2;
        Object callback = i % 2 == 0 ? callback1 : null;
        Mockito.when(event.getRegion()).thenReturn(region);
        Mockito.when(event.getKey()).thenReturn(i);
        Mockito.when(event.getCallbackArgument()).thenReturn(callback);
        switch(i % 4) {
            case 0:
            case 1:
                final EntrySnapshot entry = mock(EntrySnapshot.class);
                when(entry.getRawValue(true)).thenReturn(i);
                when(region.getEntry(eq(i))).thenReturn(entry);
                break;
            case 2:
            case 3:
                // Do nothing, get value will return a destroy
                break;
        }
        events.add(event);
    }
    listener.processEvents(events);
    verify(repo1, atLeast(numEntries / 4)).delete(any());
    verify(repo1, atLeast(numEntries / 4)).update(any(), any());
    verify(repo2, atLeast(numEntries / 4)).delete(any());
    verify(repo2, atLeast(numEntries / 4)).update(any(), any());
    verify(repo1, times(1)).commit();
    verify(repo2, times(1)).commit();
}
Also used : IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 10 with EntrySnapshot

use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.

the class LuceneGetPageFunctionJUnitTest method shouldReturnMapWithKeyAndValue.

@Test
public void shouldReturnMapWithKeyAndValue() {
    PartitionedRegion region = mock(PartitionedRegion.class);
    InternalRegionFunctionContext context = mock(InternalRegionFunctionContext.class);
    when(context.getDataSet()).thenReturn(region);
    ResultSender resultSender = mock(ResultSender.class);
    when(context.getResultSender()).thenReturn(resultSender);
    LuceneGetPageFunction function = new LuceneGetPageFunction();
    when(context.getLocalDataSet(any())).thenReturn(region);
    final EntrySnapshot entry = mock(EntrySnapshot.class);
    when(region.getEntry(any())).thenReturn(entry);
    final RegionEntry regionEntry = mock(RegionEntry.class);
    when(entry.getRegionEntry()).thenReturn(regionEntry);
    when(regionEntry.getValue(any())).thenReturn("value");
    when(context.getFilter()).thenReturn((Set) Collections.singleton("key"));
    function.execute(context);
    PageResults expectedResults = new PageResults();
    expectedResults.add(new PageEntry("key", "value"));
    verify(resultSender).lastResult(eq(expectedResults));
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) RegionEntry(org.apache.geode.internal.cache.RegionEntry) ResultSender(org.apache.geode.cache.execute.ResultSender) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)16 Region (org.apache.geode.cache.Region)7 RegionEntry (org.apache.geode.internal.cache.RegionEntry)7 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)7 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 Entry (org.apache.geode.cache.Region.Entry)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 Test (org.junit.Test)4 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 NonLocalRegionEntry (org.apache.geode.internal.cache.NonLocalRegionEntry)2 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)2 Tombstone (org.apache.geode.internal.cache.Token.Tombstone)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1