Search in sources :

Example 6 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class CacheStatisticsDUnitTest method testHitMissCount.

//////// Test methods
/**
   * Tests that the {@link CacheStatistics#getHitCount hit count} and
   * {@link CacheStatistics#getMissCount miss count} are updated properly for a local region and its
   * entries.
   */
@Test
public void testHitMissCount() throws CacheException {
    String name = this.getUniqueName();
    // value exists
    Object key = "KEY";
    // no entry
    Object key2 = "KEY2";
    // entry, invalid
    Object key3 = "KEY3";
    Object value = "VALUE";
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setStatisticsEnabled(true);
    Region region = createRegion(name, factory.create());
    CacheStatistics rStats = region.getStatistics();
    assertEquals(0, rStats.getHitCount());
    assertEquals(0, rStats.getMissCount());
    assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
    assertNull(region.get(key));
    assertEquals(0, rStats.getHitCount());
    assertEquals(1, rStats.getMissCount());
    assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
    assertNull(region.get(key));
    assertEquals(0, rStats.getHitCount());
    assertEquals(2, rStats.getMissCount());
    assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
    rStats.resetCounts();
    assertEquals(0, rStats.getHitCount());
    assertEquals(0, rStats.getMissCount());
    assertEquals(0.0f, rStats.getHitRatio(), 0.0f);
    region.put(key, value);
    assertEquals(0, rStats.getHitCount());
    assertEquals(0, rStats.getMissCount());
    CacheStatistics eStats = region.getEntry(key).getStatistics();
    assertEquals(0, eStats.getHitCount());
    assertEquals(0, eStats.getMissCount());
    assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
    region.get(key);
    assertEquals(1, eStats.getHitCount());
    assertEquals(0, eStats.getMissCount());
    assertEquals(1.0f, eStats.getHitRatio(), 0.0f);
    assertEquals(1, rStats.getHitCount());
    assertEquals(0, rStats.getMissCount());
    assertEquals(1.0f, rStats.getHitRatio(), 0.0f);
    region.get(key2);
    // assert independent from eStats
    assertEquals(1, eStats.getHitCount());
    assertEquals(0, eStats.getMissCount());
    assertEquals(1.0f, eStats.getHitRatio(), 0.0f);
    assertEquals(1, rStats.getHitCount());
    assertEquals(1, rStats.getMissCount());
    assertEquals(0.5f, rStats.getHitRatio(), 0.0f);
    region.create(key3, null);
    CacheStatistics e3Stats = region.getEntry(key3).getStatistics();
    assertEquals(0, e3Stats.getHitCount());
    assertEquals(0, e3Stats.getMissCount());
    assertEquals(0.0f, e3Stats.getHitRatio(), 0.0f);
    // miss on existing entry
    region.get(key3);
    assertEquals(0, e3Stats.getHitCount());
    assertEquals(1, e3Stats.getMissCount());
    assertEquals(0.0f, e3Stats.getHitRatio(), 0.0f);
    assertEquals(1, rStats.getHitCount());
    assertEquals(2, rStats.getMissCount());
    assertEquals(0.33f, rStats.getHitRatio(), 0.01f);
    eStats.resetCounts();
    assertEquals(0, eStats.getHitCount());
    assertEquals(0, eStats.getMissCount());
    assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
    rStats.resetCounts();
    region.invalidate(key);
    assertEquals(0, eStats.getHitCount());
    assertEquals(0, eStats.getMissCount());
    assertEquals(0.0f, eStats.getHitRatio(), 0.0f);
    region.get(key);
    assertEquals(0, eStats.getHitCount());
    assertEquals(1, eStats.getMissCount());
    assertEquals(0, rStats.getHitCount());
    assertEquals(1, rStats.getMissCount());
    region.destroy(key);
    try {
        eStats.getMissCount();
        fail("Should have thrown an EntryDestroyedException");
    } catch (EntryDestroyedException ex) {
    // pass...
    }
}
Also used : CacheStatistics(org.apache.geode.cache.CacheStatistics) AttributesFactory(org.apache.geode.cache.AttributesFactory) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class LocalRegion method clearViaFilterClass.

/**
   * do a localDestroy on all matching keys
   *
   * @param key the regular expression to match on
   */
private void clearViaFilterClass(String key) {
    InterestFilter filter;
    try {
        Class filterClass = ClassLoadUtil.classFromName(key);
        filter = (InterestFilter) filterClass.newInstance();
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(LocalizedStrings.LocalRegion_CLASS_0_NOT_FOUND_IN_CLASSPATH.toLocalizedString(key), cnfe);
    } catch (Exception e) {
        throw new RuntimeException(LocalizedStrings.LocalRegion_CLASS_0_COULD_NOT_BE_INSTANTIATED.toLocalizedString(key), e);
    }
    for (Object entryObject : entrySet(false)) {
        Entry entry = (Entry) entryObject;
        try {
            Object entryKey = entry.getKey();
            if (!(entryKey instanceof String)) {
                continue;
            }
            InterestEvent e = new InterestEvent(entryKey, entry.getValue(), true);
            if (!filter.notifyOnRegister(e)) {
                // the filter does not want to know about this entry, so skip it.
                continue;
            }
            localDestroyNoCallbacks(entryKey);
        } catch (EntryDestroyedException ignore) {
        // ignore to fix bug 35534
        }
    }
}
Also used : LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) StoredObject(org.apache.geode.internal.offheap.StoredObject) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException)

Example 8 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class LocalRegion method clearViaRegEx.

/**
   * do a localDestroy on all matching keys
   *
   * @param key the regular expression to match on
   * @see #registerInterestRegex(String)
   */
private void clearViaRegEx(String key) {
    // TODO: if (key.equals(".*)) then cmnClearRegionNoCallbacks
    Pattern keyPattern = Pattern.compile(key);
    for (Iterator it = this.entrySet(false).iterator(); it.hasNext(); ) {
        Region.Entry entry = (Region.Entry) it.next();
        try {
            Object entryKey = entry.getKey();
            if (!(entryKey instanceof String)) {
                continue;
            }
            if (!keyPattern.matcher((String) entryKey).matches()) {
                // key does not match the regex, this entry should not be returned.
                continue;
            }
            localDestroyNoCallbacks(entryKey);
        } catch (EntryDestroyedException ignore) {
        // ignore to fix bug 35534
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 9 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class HAInterestPart2DUnitTest method testBug35945.

/**
   * Bug Test for Bug # 35945 A java level Deadlock between acquireConnection and RegionEntry during
   * processRecoveredEndpoint by Dead Server Monitor Thread.
   *
   * @throws Exception
   */
@Test
public void testBug35945() throws Exception {
    PORT1 = ((Integer) server1.invoke(() -> HAInterestTestCase.createServerCache())).intValue();
    server1.invoke(() -> HAInterestTestCase.createEntriesK1andK2());
    createClientPoolCacheConnectionToSingleServer(this.getName(), NetworkUtils.getServerHostName(server1.getHost()));
    registerK1AndK2();
    verifyRefreshedEntriesFromServer();
    server1.invoke(() -> HAInterestTestCase.stopServer());
    verifyDeadAndLiveServers(1, 0);
    // put on stopped server
    server1.invoke(() -> HAInterestTestCase.putK1andK2());
    // spawn a thread to put on server , which will acquire a lock on entry
    setClientServerObserverForBeforeInterestRecovery();
    server1.invoke(() -> HAInterestTestCase.startServer());
    verifyDeadAndLiveServers(0, 1);
    waitForBeforeInterestRecoveryCallBack();
    // verify updated value of k1 as a refreshEntriesFromServer
    final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r1);
    WaitCriterion wc = new WaitCriterion() {

        private String excuse;

        @Override
        public boolean done() {
            Region.Entry e1 = r1.getEntry(k1);
            Region.Entry e2 = r1.getEntry(k2);
            Object v1 = null;
            if (e1 != null) {
                try {
                    v1 = e1.getValue();
                } catch (EntryDestroyedException ignore) {
                // handled to fix GEODE-296
                }
            }
            if (e1 == null || !server_k1_updated.equals(v1)) {
                excuse = "v1=" + v1;
                return false;
            }
            Object v2 = null;
            if (e2 != null) {
                try {
                    v2 = e2.getValue();
                } catch (EntryDestroyedException ignore) {
                // handled to fix GEODE-296
                }
            }
            if (e2 == null || !server_k2.equals(v2)) {
                excuse = "v2=" + v2;
                return false;
            }
            return true;
        }

        @Override
        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 10 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class HAInterestPart2DUnitTest method testRefreshEntriesFromPrimaryWhenDSMDetectsServerLive.

/**
   * Tests a Scenario: Only one server, register interest on the server stop server , and update the
   * registered entries on the server start the server , DSM will recover interest list on this live
   * server and verify that as a part of recovery it refreshes registered entries from the server,
   * because it is primary
   */
@Test
public void testRefreshEntriesFromPrimaryWhenDSMDetectsServerLive() throws Exception {
    IgnoredException.addIgnoredException(ServerConnectivityException.class.getName());
    PORT1 = ((Integer) server1.invoke(() -> HAInterestTestCase.createServerCache())).intValue();
    server1.invoke(() -> HAInterestTestCase.createEntriesK1andK2());
    createClientPoolCacheConnectionToSingleServer(this.getName(), NetworkUtils.getServerHostName(server1.getHost()));
    registerK1AndK2();
    verifyRefreshedEntriesFromServer();
    server1.invoke(() -> HAInterestTestCase.stopServer());
    verifyDeadAndLiveServers(1, 0);
    server1.invoke(() -> HAInterestTestCase.putK1andK2());
    server1.invoke(() -> HAInterestTestCase.startServer());
    verifyDeadAndLiveServers(0, 1);
    final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r1);
    // Verify for interest registration after cache-server is started.
    server1.invoke(() -> HAInterestTestCase.verifyInterestRegistration());
    WaitCriterion wc = new WaitCriterion() {

        private String excuse;

        @Override
        public boolean done() {
            Region.Entry e1;
            Region.Entry e2;
            try {
                e1 = r1.getEntry(k1);
                if (e1 == null) {
                    excuse = "Entry for k1 is null";
                    return false;
                }
            } catch (EntryDestroyedException e) {
                excuse = "Entry destroyed";
                return false;
            }
            if (!server_k1.equals(e1.getValue())) {
                excuse = "e1 value is not server_k1";
                return false;
            }
            try {
                e2 = r1.getEntry(k2);
                if (e2 == null) {
                    excuse = "Entry for k2 is null";
                    return false;
                }
            } catch (EntryDestroyedException e) {
                excuse = "Entry destroyed";
                return false;
            }
            if (!server_k2.equals(e2.getValue())) {
                excuse = "e2 value is not server_k2";
                return false;
            }
            return true;
        }

        @Override
        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)28 Region (org.apache.geode.cache.Region)12 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)5 LRUEntry (org.apache.geode.internal.cache.lru.LRUEntry)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 DiskAccessException (org.apache.geode.cache.DiskAccessException)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Test (org.junit.Test)4 ByteBuf (io.netty.buffer.ByteBuf)3 Entry (java.util.Map.Entry)3 NoSuchElementException (java.util.NoSuchElementException)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 IOException (java.io.IOException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 RollbackException (javax.transaction.RollbackException)2