@Override public boolean containsKey(Object key) { return map.containsKey(key); }
/** * Test for bug 43407, where LRU in the client caused an entry to be evicted with DESTROY(), then * the client invalidated the entry and did a get(). After the get() the entry was not seen to be * in the client's cache. This turned out to be expected behavior, but we now have this test to * guarantee that the product behaves as expected. */ @Test public void testGetInClientCreatesEntry() throws Exception { // start server first PORT1 = initServerCache(false); createClientCache(NetworkUtils.getServerHostName(), PORT1); registerInterestForInvalidatesInBothTheRegions(); Region region = static_cache.getRegion(REGION_NAME1); populateCache(); region.put("invalidationKey", "invalidationValue"); region.localDestroy("invalidationKey"); assertThat(region.containsKey("invalidationKey")).isFalse(); region.invalidate("invalidationKey"); assertThat(region.containsKey("invalidationKey")).isTrue(); Object value = region.get("invalidationKey"); assertThat(value).isNull(); assertThat(region.containsKeyOnServer("invalidationKey")).isTrue(); }
public boolean containsKey(Object key) { return this.region.containsKey(key); }
public boolean keyExistsInLocalMonitoringRegion(String key) { if (localMonitoringRegion != null && !localMonitoringRegion.isDestroyed()) { // We want to just check locally without sending a message to the manager. // containsKey does this. return localMonitoringRegion.containsKey(key); } else { return true; // so caller will think it does not need to do a putAll } }
public boolean existsKey(ByteArrayWrapper key) { return this.redisMetaRegion.containsKey(key.toString()); }
@Override public boolean containsKey(Object key) { try { preOp(); return this.realRegion.containsKey(key); } finally { postOp(); } }
@Before public void setUp() throws Exception { regionStub = mock(Region.class); when(regionStub.remove(TEST_KEY)).thenReturn(TEST_VALUE); when(regionStub.containsKey(TEST_KEY)).thenReturn(true); when(regionStub.containsKey(MISSING_KEY)).thenReturn(false); when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub); when(cacheStub.getRegion(MISSING_REGION)).thenReturn(null); operationHandler = new RemoveRequestOperationHandler(); }
@Before public void setUp() throws Exception { Region regionStub = mock(Region.class); when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE); when(regionStub.get(MISSING_KEY)).thenReturn(null); when(regionStub.get(NULLED_KEY)).thenReturn(null); when(regionStub.containsKey(MISSING_KEY)).thenReturn(false); when(regionStub.containsKey(NULLED_KEY)).thenReturn(true); when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub); when(cacheStub.getRegion(MISSING_REGION)).thenReturn(null); operationHandler = new GetRequestOperationHandler(); }
protected void verify100Int(boolean verifySize) { if (verifySize) { assertEquals(100, region.size()); } for (int i = 0; i < 100; i++) { Integer key = i; assertTrue(region.containsKey(key)); assertEquals(key, region.get(key)); } }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Region region = mock(LocalRegion.class); when(region.containsKey(isA(String.class))).thenReturn(true); InternalCache cache = mock(InternalCache.class); when(cache.getRegion(isA(String.class))).thenReturn(region); CacheServerStats cacheServerStats = mock(CacheServerStats.class); when(this.serverConnection.getCache()).thenReturn(cache); when(this.serverConnection.getCacheServerStats()).thenReturn(cacheServerStats); when(this.serverConnection.getResponseMessage()).thenReturn(this.replyMessage); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); Part regionNamePart = mock(Part.class); when(regionNamePart.getString()).thenReturn(REGION_NAME); Part keyPart = mock(Part.class); when(keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getPart(eq(0))).thenReturn(regionNamePart); when(this.message.getPart(eq(1))).thenReturn(keyPart); }
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); }
@Override public void run2() { Region<String, Object> rgn1 = getRootRegion().getSubregion(rgnName); CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager(); MyTransactionListener<String, Object> tl = firstTransactionListenerFrom(txMgr2); assertThat(rgn1.containsKey("key")).isFalse(); assertThat(rgn1.containsValueForKey("key")).isFalse(); tl.assertCounts(3, 0, 0, 0); { Collection<EntryEvent<String, Object>> events = TxEventTestUtil.getDestroyEvents(tl.lastEvent.getEvents()); assertThat(events.size()).isEqualTo(1); EntryEvent<String, Object> ev = events.iterator().next(); assertThat(rgn1).isSameAs(ev.getRegion()); assertThat(ev.getKey()).isNull(); assertThat(ev.getNewValue()).isNull(); assertThat(ev.getOldValue()).isNull(); assertThat(ev.getOperation().isLocalLoad()).isFalse(); assertThat(ev.getOperation().isNetLoad()).isFalse(); assertThat(ev.getOperation().isLoad()).isFalse(); assertThat(ev.getOperation().isNetSearch()).isFalse(); assertThat(ev.getOperation().isExpiration()).isFalse(); assertThat(ev.getCallbackArgument()).isNull(); assertThat(ev.isCallbackArgumentAvailable()).isTrue(); assertThat(ev.isOriginRemote()).isTrue(); assertThat(ev.getOperation().isDistributed()).isTrue(); } } });
private boolean setXX(Region<ByteArrayWrapper, ByteArrayWrapper> r, Command command, ByteArrayWrapper key, ByteArrayWrapper valueWrapper, ExecutionHandlerContext context) { if (r.containsKey(key)) { checkAndSetDataType(key, context); r.put(key, valueWrapper); command.setResponse(Coder.getSimpleStringResponse(context.getByteBufAllocator(), SUCCESS)); return true; } else { command.setResponse(Coder.getNilResponse(context.getByteBufAllocator())); return false; } }
@Override public void addRemoteType(int typeId, PdxType type) { verifyConfiguration(); TXStateProxy currentState = suspendTX(); Region<Object, Object> r = getIdToType(); try { if (!r.containsKey(typeId)) { // This type could actually be for this distributed system, // so we need to make sure the type is published while holding // the distributed lock. lock(); try { r.putIfAbsent(typeId, type); } finally { unlock(); } } } finally { resumeTX(currentState); } }
@Override public void addRemoteEnum(int id, EnumInfo enumInfo) { verifyConfiguration(); TXStateProxy currentState = suspendTX(); EnumId enumId = new EnumId(id); Region<Object, Object> r = getIdToType(); try { if (!r.containsKey(enumId)) { // This enum could actually be for this distributed system, // so we need to make sure the enum is published while holding // the distributed lock. lock(); try { r.put(enumId, enumInfo); } finally { unlock(); } } } finally { resumeTX(currentState); } }
@Override public void executeCommand(Command command, ExecutionHandlerContext context) { List<byte[]> commandElems = command.getProcessedCommand(); if (commandElems.size() < 3) { command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HEXISTS)); return; } ByteArrayWrapper key = command.getKey(); checkDataType(key, RedisDataType.REDIS_HASH, context); Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key); if (keyRegion == null) { command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS)); return; } byte[] byteField = commandElems.get(FIELD_INDEX); ByteArrayWrapper field = new ByteArrayWrapper(byteField); boolean hasField = keyRegion.containsKey(field); if (hasField) command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), EXISTS)); else command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS)); }
@Override public void executeCommand(Command command, ExecutionHandlerContext context) { List<byte[]> commandElems = command.getProcessedCommand(); if (commandElems.size() < 3) { command .setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.SISMEMBER)); return; } ByteArrayWrapper key = command.getKey(); ByteArrayWrapper member = new ByteArrayWrapper(commandElems.get(2)); checkDataType(key, RedisDataType.REDIS_SET, context); @SuppressWarnings("unchecked") Region<ByteArrayWrapper, Boolean> keyRegion = (Region<ByteArrayWrapper, Boolean>) context.getRegionProvider().getRegion(key); if (keyRegion == null) { command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS)); return; } if (keyRegion.containsKey(member)) command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), EXISTS)); else command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS)); }
void buildDetails(Region r, Object objName, int inspectionType) { try { objName = getObjectName(r, objName); if (cancelled) return; if (r.containsKey(objName)) { if (cancelled) return; // @todo darrel: race condition; could be unloaded between isPresent and get call. Region.Entry e = r.getEntry(objName); Object v = e.getValue(); if (cancelled) return; objectValue = CacheDisplay.getCachedObjectDisplay(v, inspectionType); if (cancelled) return; userAttribute = CacheDisplay.getCachedObjectDisplay(e.getUserAttribute(), inspectionType); if (cancelled) return; try { stats = new RemoteCacheStatistics(e.getStatistics()); } catch (StatisticsDisabledException ignore) { } } } catch (CacheException ex) { throw new GemFireCacheException(ex); } }
public void remoteTestPostSnapshot(String name, boolean isController, boolean isRoot) throws CacheException { assertTrue(preSnapshotRegion.isDestroyed()); try { preSnapshotRegion.get("0"); fail("Should have thrown a RegionReinitializedException"); } catch (RegionReinitializedException e) { // pass } LogWriter log = getCache().getLogger(); // get new reference to region Region postSnapshotRegion = isRoot ? getRootRegion(name) : getRootRegion().getSubregion(name); assertNotNull("Could not get reference to reinitialized region", postSnapshotRegion); boolean expectData = isController || postSnapshotRegion.getAttributes().getMirrorType().isMirrored() || postSnapshotRegion.getAttributes().getDataPolicy().isPreloaded(); log.info("region has " + postSnapshotRegion.keySet().size() + " entries"); assertEquals(expectData ? MAX_KEYS : 0, postSnapshotRegion.keySet().size()); // gets the data either locally or by netSearch assertEquals(new Integer(3), postSnapshotRegion.get("3")); // bug 33311 coverage if (expectData) { assertFalse(postSnapshotRegion.containsValueForKey("9")); assertTrue(postSnapshotRegion.containsKey("9")); } }
/** * Tests that creating an entry in a region actually creates it * * @see Region#containsKey * @see Region#containsValueForKey */ @Test public void testContainsKey() throws CacheException { String name = this.getUniqueName(); Region region = createRegion(name); Object key = name; Object value = new Integer(42); assertFalse(region.containsKey(key)); region.create(key, null); assertFalse(region.containsValueForKey(key)); Region.Entry entry = region.getEntry(key); assertNotNull(entry); assertEquals(entry.getKey(), key); assertNull(entry.getValue()); region.put(key, value); assertTrue(region.containsValueForKey(key)); assertEquals(entry, region.getEntry(key)); if (entry.isLocal()) { assertEquals(value, entry.getValue()); } else { assertEquals(value, region.getEntry(key).getValue()); } }