@Override public void visit(Integer bid, Entry re) { buf.append(re.getKey()).append(" => ").append(re.getValue()).append("\n"); }
@Override public void visit(Integer bucketId, Entry re) { if (re.getValue() != Token.TOMBSTONE) { al.add(re); } }
@Override public void run2() throws CacheException { Region<Object, Object> region = getRootRegion().getSubregion(name); Region.Entry entry = region.getEntry(key); assertThat(entry).isNotNull(); assertThat(entry.getValue()).isEqualTo(newValue); } });
/** * Tests invalidating a region entry */ @Test public void testInvalidateEntry() throws CacheException { String name = this.getUniqueName(); Object key = "KEY"; Object value = "VALUE"; Region region = createRegion(name); region.put(key, value); int beforeInvalidates = ((org.apache.geode.internal.cache.GemFireCacheImpl) getCache()) .getCachePerfStats().getInvalidates(); Region.Entry entry = region.getEntry(key); region.invalidate(key); if (entry.isLocal()) { assertNull(entry.getValue()); } assertNull(region.get(key)); int afterInvalidates = ((org.apache.geode.internal.cache.GemFireCacheImpl) getCache()) .getCachePerfStats().getInvalidates(); assertEquals("Invalidate CachePerfStats incorrect", beforeInvalidates + 1, afterInvalidates); }
private static void doLocalGetsP(final int num, final boolean checkNVals) { assertTrue(num <= KEYS.length); String[] vals = VALUES; if (checkNVals) { vals = NVALUES; } final Region region = getCache().getRegion(REGION_NAME); assertNotNull(region); for (int index = 0; index < num; ++index) { final String key = KEYS[index]; final String expectedVal = vals[index]; await() .until(() -> expectedVal.equals(getLocalValue(region, key))); } for (int index = 0; index < num; ++index) { Region.Entry entry = region.getEntry(KEYS[index]); assertNotNull(entry); assertEquals(vals[index], entry.getValue()); } }
@Override public boolean hasNext() { if (nextValue != null) { return true; } while (nextValue == null) { if (!super.hasNext()) { return false; } this.key.setKey(super.next()); this.key.setBucketId(this.currentBucketId); Region.Entry re = (Region.Entry) view.getEntryForIterator(key, PartitionedRegion.this, rememberReads, allowTombstones); if (re != null) { nextValue = re.getValue(); } } return true; }
public static void populateCache() { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1); Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r1); assertNotNull(r2); if (!r1.containsKey(k1)) r1.create(k1, k1); if (!r1.containsKey(k2)) r1.create(k2, k2); if (!r2.containsKey(k1)) r2.create(k1, k1); if (!r2.containsKey(k2)) r2.create(k2, k2); assertEquals(r1.getEntry(k1).getValue(), k1); assertEquals(r1.getEntry(k2).getValue(), k2); assertEquals(r2.getEntry(k1).getValue(), k1); assertEquals(r2.getEntry(k2).getValue(), k2); }
private static void verifyInvalidatesOnBothRegions() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1); final Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r1); assertNotNull(r2); await() .until(() -> r1.getEntry(k1).getValue() == null); await() .until(() -> r1.getEntry(k2).getValue() == null); await() .until(() -> r2.getEntry(k1).getValue() == null); await() .until(() -> r2.getEntry(k2).getValue() == null); } catch (Exception ex) { fail("failed while verifyInvalidatesOnBothRegions()" + ex); } }
/** * Generates XML for a region entry */ private void generate(Region.Entry entry) throws SAXException { if ((entry == null)) { return; } handler.startElement("", ENTRY, ENTRY, EMPTY); handler.startElement("", KEY, KEY, EMPTY); generate(entry.getKey()); handler.endElement("", KEY, KEY); handler.startElement("", VALUE, VALUE, EMPTY); generate(entry.getValue()); handler.endElement("", VALUE, VALUE); handler.endElement("", ENTRY, ENTRY); }
public static void put() { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1); Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r1); assertNotNull(r2); r1.put(k1, server_k1); r1.put(k2, server_k2); r2.put(k1, server_k1); r2.put(k2, server_k2); assertEquals(r1.getEntry(k1).getValue(), server_k1); assertEquals(r1.getEntry(k2).getValue(), server_k2); assertEquals(r2.getEntry(k1).getValue(), server_k1); assertEquals(r2.getEntry(k2).getValue(), server_k2); }
private Object getValueForCallback(LocalRegion r, Object k) { Region.Entry<?, ?> e = r.getEntry(k); return (e != null) ? e.getValue() : null; }
private static void verifyUpdatesOnRegion2() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); final Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2); assertNotNull(r2); await() .until(() -> server_k1.equals(r2.getEntry(k1).getValue())); await() .until(() -> server_k2.equals(r2.getEntry(k2).getValue())); // assertIndexDetailsEquals(server_k2, r2.getEntry(k2).getValue()); } catch (Exception ex) { fail("failed while verifyUpdatesOnRegion2()" + ex); } }
@Override public boolean containsTombstone(Object key) { checkReadiness(); checkForNoAccess(); if (!this.getConcurrencyChecksEnabled()) { return false; } else { try { Entry entry = getDataView().getEntry(getKeyInfo(key), this, true); return entry != null && entry.getValue() == Token.TOMBSTONE; } catch (EntryDestroyedException ignore) { return true; } } }
@Test public void lockQueryWithoutProjectionWithMatchingResultShouldReturnCorrectValue() throws Exception { String value = "value"; when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); Region.Entry entry = mock(Region.Entry.class); when(entry.getValue()).thenReturn(value); when(region.accessEntry(eq("key"), anyBoolean())).thenReturn(entry); List results = new LinkedList(); index.lockedQuery("key", OQLLexerTokenTypes.TOK_EQ, results, null, context); assertEquals(value, results.get(0)); }
@Test public void lockQueryWithoutProjectionWithMatchingResultForCqShouldReturnCorrectCqEvent() throws Exception { String value = "value"; when(context.isCqQueryContext()).thenReturn(true); when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); Region.Entry entry = mock(Region.Entry.class); when(entry.getValue()).thenReturn(value); when(region.accessEntry(eq("key"), anyBoolean())).thenReturn(entry); List results = new LinkedList(); index.lockedQuery("key", OQLLexerTokenTypes.TOK_EQ, results, null, context); assertTrue(results.get(0) instanceof CqEntry); }
@Override public void run2() { Region rgn1 = getRootRegion().getSubregion(rgnName); CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager(); MyTransactionListener<String, String> tl = firstTransactionListenerFrom(txMgr2); assertThat(rgn1.containsKey("key")).isTrue(); assertThat(rgn1.containsValueForKey("key")).isTrue(); assertThat(rgn1.getEntry("key").getValue()).isEqualTo("value1"); tl.assertCounts(2, 0, 0, 0); // nothing happened remotely } });
protected static Object getLocalValue(final Region region, final Object key) { Region.Entry entry = region.getEntry(key); if (entry != null) { try { // Handle race conditions with concurrent destroy ops return entry.getValue(); } catch (EntryDestroyedException e) { return null; } } else { return null; } }
@Override public Object getEntry(Object key) { Region.Entry entry = ((Region) map).getEntry(key); if (entry != null) { ClientUpdateMessageImpl msg = (ClientUpdateMessageImpl) entry.getValue(); msg.setEventIdentifier(((HAEventWrapper) key).getEventId()); if (msg.hasCqs()) { msg.setClientCqs(((HAEventWrapper) key).getClientCqs()); } } return entry; }