use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class PartitionedRepositoryManagerJUnitTest method setUpMockBucket.
protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException {
BucketRegion mockBucket = Mockito.mock(BucketRegion.class);
BucketRegion fileAndChunkBucket = Mockito.mock(BucketRegion.class);
// Allowing the fileAndChunkBucket to behave like a map so that the IndexWriter operations don't
// fail
Fakes.addMapBehavior(fileAndChunkBucket);
when(fileAndChunkBucket.getFullPath()).thenReturn("File" + id);
when(mockBucket.getId()).thenReturn(id);
when(userRegion.getBucketRegion(eq(id), eq(null))).thenReturn(mockBucket);
when(userDataStore.getLocalBucketById(eq(id))).thenReturn(mockBucket);
when(userRegion.getBucketRegion(eq(id + 113), eq(null))).thenReturn(mockBucket);
when(userDataStore.getLocalBucketById(eq(id + 113))).thenReturn(mockBucket);
when(fileDataStore.getLocalBucketById(eq(id))).thenReturn(fileAndChunkBucket);
fileAndChunkBuckets.put(id, fileAndChunkBucket);
dataBuckets.put(id, mockBucket);
BucketAdvisor mockBucketAdvisor = Mockito.mock(BucketAdvisor.class);
when(fileAndChunkBucket.getBucketAdvisor()).thenReturn(mockBucketAdvisor);
when(mockBucketAdvisor.isPrimary()).thenReturn(true);
return mockBucket;
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class IndexRepositoryImplJUnitTest method setUp.
@Before
public void setUp() throws IOException {
ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
fileSystemStats = mock(FileSystemStats.class);
RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
IndexWriterConfig config = new IndexWriterConfig(analyzer);
writer = new IndexWriter(dir, config);
String[] indexedFields = new String[] { "s", "i", "l", "d", "f", "s2", "missing" };
mapper = new HeterogeneousLuceneSerializer(indexedFields);
region = Mockito.mock(Region.class);
userRegion = Mockito.mock(BucketRegion.class);
BucketAdvisor bucketAdvisor = Mockito.mock(BucketAdvisor.class);
Mockito.when(bucketAdvisor.isPrimary()).thenReturn(true);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor()).thenReturn(bucketAdvisor);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor().isPrimary()).thenReturn(true);
stats = Mockito.mock(LuceneIndexStats.class);
Mockito.when(userRegion.isDestroyed()).thenReturn(false);
repo = new IndexRepositoryImpl(region, writer, mapper, stats, userRegion, mock(DistributedLockService.class), "lockName");
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.
private void createBucketRegionQueue() {
// Create InternalRegionArguments
InternalRegionArguments ira = new InternalRegionArguments();
ira.setPartitionedRegion(this.queueRegion);
ira.setPartitionedRegionBucketRedundancy(1);
BucketAdvisor ba = mock(BucketAdvisor.class);
ira.setBucketAdvisor(ba);
InternalRegionArguments pbrIra = new InternalRegionArguments();
RegionAdvisor ra = mock(RegionAdvisor.class);
when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
pbrIra.setPartitionedRegionAdvisor(ra);
PartitionAttributes pa = mock(PartitionAttributes.class);
when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
}
});
when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
when(pa.getColocatedWith()).thenReturn(null);
// classes cannot be mocked
ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
when(ba.getProxyBucketRegion()).thenReturn(pbr);
// Create RegionAttributes
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
RegionAttributes attributes = factory.create();
// Create BucketRegionQueue
BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
this.bucketRegionQueue = spy(realBucketRegionQueue);
// (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
// when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class AcceptorImpl method start.
@Override
public void start() throws IOException {
ThreadGroup tg = LoggingThreadGroup.createThreadGroup("Acceptor " + this.serverSock.getInetAddress() + ":" + this.localPort, logger);
thread = new Thread(tg, this, "Cache Server Acceptor " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort());
this.acceptorId = thread.getId();
// This thread should not be a daemon to keep BridgeServers created
// in code from exiting immediately.
thread.start();
if (isSelector()) {
Runnable r = new Runnable() {
public void run() {
AcceptorImpl.this.runSelectorLoop();
}
};
this.selectorThread = new Thread(tg, r, "Cache Server Selector " + this.serverSock.getInetAddress() + ":" + this.localPort + " local port: " + this.serverSock.getLocalPort());
this.selectorThread.start();
}
Set<PartitionedRegion> prs = this.cache.getPartitionedRegions();
for (PartitionedRegion pr : prs) {
Map<Integer, BucketAdvisor.BucketProfile> profiles = new HashMap<Integer, BucketAdvisor.BucketProfile>();
// get all local real bucket advisors
Map<Integer, BucketAdvisor> advisors = pr.getRegionAdvisor().getAllBucketAdvisors();
for (Map.Entry<Integer, BucketAdvisor> entry : advisors.entrySet()) {
BucketAdvisor advisor = entry.getValue();
// addLocally
BucketProfile bp = (BucketProfile) advisor.createProfile();
advisor.updateServerBucketProfile(bp);
// advisor.basicAddClientProfile(bp);
profiles.put(entry.getKey(), bp);
}
Set receipients = new HashSet();
receipients = pr.getRegionAdvisor().adviseAllPRNodes();
// send it to all in one messgae
ReplyProcessor21 reply = AllBucketProfilesUpdateMessage.send(receipients, pr.getDistributionManager(), pr.getPRId(), profiles, true);
if (reply != null) {
reply.waitForRepliesUninterruptibly();
}
}
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class BucketCountLoadProbe method getLoad.
public PRLoad getLoad(PartitionedRegion pr) {
PartitionedRegionDataStore ds = pr.getDataStore();
int configuredBucketCount = pr.getTotalNumberOfBuckets();
PRLoad prLoad = new PRLoad(configuredBucketCount, pr.getLocalMaxMemory());
// key: bid, value: size
for (Integer bidInt : ds.getAllLocalBucketIds()) {
int bid = bidInt.intValue();
BucketAdvisor bucketAdvisor = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor();
// Wait for a primary to exist for this bucket, because
// it might be this member.
bucketAdvisor.getPrimary();
boolean isPrimary = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor().isPrimary();
prLoad.addBucket(bid, 1, isPrimary ? 1 : 0);
}
return prLoad;
}
Aggregations