use of org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse in project geode by apache.
the class FetchEntriesMessageJUnitTest method testProcessChunk.
@Test
public void testProcessChunk() throws Exception {
cache = Fakes.cache();
PartitionedRegion pr = mock(PartitionedRegion.class);
InternalDistributedSystem system = cache.getInternalDistributedSystem();
FetchEntriesResponse response = new FetchEntriesResponse(system, pr, null, 0);
HeapDataOutputStream chunkStream = createDummyChunk();
FetchEntriesReplyMessage reply = new FetchEntriesReplyMessage(null, 0, 0, chunkStream, 0, 0, 0, false, false);
reply.chunk = chunkStream.toByteArray();
response.processChunk(reply);
assertNull(response.returnRVV);
assertEquals(2, response.returnValue.size());
assertTrue(response.returnValue.get("keyWithOutVersionTag").equals("valueWithOutVersionTag"));
assertTrue(response.returnValue.get("keyWithVersionTag").equals("valueWithVersionTag"));
assertNull(response.returnVersions.get("keyWithOutVersionTag"));
assertNotNull(response.returnVersions.get("keyWithVersionTag"));
}
use of org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse in project geode by apache.
the class PartitionedRegion method getAllBucketEntries.
/**
* Test Method: Get all entries for all copies of a bucket
*
* This method will not work correctly if membership in the distributed system changes while the
* result is being calculated.
*
* @return a List of HashMaps, each map being a copy of the entries in a bucket
*/
public List<BucketDump> getAllBucketEntries(final int bucketId) throws ForceReattemptException {
if (bucketId >= getTotalNumberOfBuckets()) {
return Collections.emptyList();
}
ArrayList<BucketDump> ret = new ArrayList<BucketDump>();
HashSet<InternalDistributedMember> collected = new HashSet<InternalDistributedMember>();
for (; ; ) {
// Collect all the candidates by re-examining the advisor...
Set<InternalDistributedMember> owners = getRegionAdvisor().getBucketOwners(bucketId);
// Remove ones we've already polled...
owners.removeAll(collected);
// Terminate if no more entries
if (owners.isEmpty()) {
break;
}
// Get first entry
Iterator<InternalDistributedMember> ownersI = owners.iterator();
InternalDistributedMember owner = (InternalDistributedMember) ownersI.next();
// Remove it from our list
collected.add(owner);
// If it is ourself, answer directly
if (owner.equals(getMyId())) {
BucketRegion br = this.dataStore.handleRemoteGetEntries(bucketId);
Map<Object, Object> m = new HashMap<Object, Object>() {
// TODO: clean this up -- outer class is not serializable
private static final long serialVersionUID = 0L;
@Override
public String toString() {
return "Bucket id = " + bucketId + " from local member = " + getDistributionManager().getDistributionManagerId() + ": " + super.toString();
}
};
Map<Object, VersionTag> versions = new HashMap<Object, VersionTag>();
for (Iterator<Map.Entry> it = br.entrySet().iterator(); it.hasNext(); ) {
LocalRegion.NonTXEntry entry = (LocalRegion.NonTXEntry) it.next();
RegionEntry re = entry.getRegionEntry();
// OFFHEAP: incrc, deserialize, decrc
Object value = re.getValue(br);
VersionStamp versionStamp = re.getVersionStamp();
VersionTag versionTag = versionStamp != null ? versionStamp.asVersionTag() : null;
if (versionTag != null) {
versionTag.replaceNullIDs(br.getVersionMember());
}
if (Token.isRemoved(value)) {
continue;
} else if (Token.isInvalid(value)) {
value = null;
} else if (value instanceof CachedDeserializable) {
value = ((CachedDeserializable) value).getDeserializedForReading();
}
m.put(re.getKey(), value);
versions.put(re.getKey(), versionTag);
}
RegionVersionVector rvv = br.getVersionVector();
rvv = rvv != null ? rvv.getCloneForTransmission() : null;
ret.add(new BucketDump(bucketId, owner, rvv, m, versions));
continue;
}
// Send a message
try {
final FetchEntriesResponse r;
r = FetchEntriesMessage.send(owner, this, bucketId);
ret.add(r.waitForEntries());
} catch (ForceReattemptException ignore) {
// node has departed? Ignore.
}
}
return ret;
}
Aggregations