You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geode.apache.org by Avinash Dongre <do...@gmail.com> on 2016/07/11 14:18:21 UTC
Client Cache Behavior after ForcedDisconnectException
Hi All,
I want to understand the Client-Cache Behavior after for some reason
server is getting reconnected due to ForcedDisconnectException.
1. Do I need to create client cache again, and Regions ?
I tried to write following Tests but it is failing , Please help.
private void forcedDisconnectAndReconnectEachVM() {
new ArrayList<>(Arrays.asList(vm0/*, vm1, vm2*/)).
forEach((VM) -> VM.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
GemFireCacheImpl oldCache = (GemFireCacheImpl)
CacheFactory.getAnyInstance();
assertNotNull(oldCache);
InternalDistributedSystem distributedSystem =
(InternalDistributedSystem) oldCache.getDistributedSystem();
assertNotNull(distributedSystem);
MembershipManagerHelper.crashDistributedSystem(distributedSystem);
return null;
}
}));
}
private void updateServerCacheAfterReconnect() {
new ArrayList<>(Arrays.asList(vm0/*, vm1, vm2*/)).
forEach((VM) -> VM.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
cache = cache.getReconnectedCache();
return null;
}
}));
}
public void testForcedDisconnectException() {
createRegionInEachVM();
ClientCache clientCache = ClientCacheFactory.getAnyInstance();
ClientRegionFactory<String, String> crf =
clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<String, String> test_pr_region = crf.create("TEST_PR_REGION");
for (int i = 0; i < 10; i++) {
test_pr_region.put("Key" + i, "Value" + i);
}
forcedDisconnectAndReconnectEachVM();
updateServerCacheAfterReconnect();
createRegionInEachVM();
for (int i = 0; i < 10; i++) {
final String s = test_pr_region.get("Key" + i);
assertEquals("Value" + i , s);
}
}
Re: Client Cache Behavior after ForcedDisconnectException
Posted by Bruce Schuchardt <bs...@pivotal.io>.
You won't be able to fish for the old cache like this. Once it is
disrupted with a ForceDisconnectException the old cache won't be
returned by CacheFactory.getAnyInstance(). You'll need to retain a
reference to the old cache in the test and use that instead.
Client caches shouldn't need to be rebuilt.
Le 7/11/2016 � 11:16 AM, Swapnil Bawaskar a �crit :
> private void updateServerCacheAfterReconnect() {
> > new ArrayList<>(Arrays.asList(vm0/*, vm1, vm2*/)).
> > forEach((VM) -> VM.invoke(new SerializableCallable() {
> > @Override
> > public Object call() throws Exception {
> > Cache cache = CacheFactory.getAnyInstance();
> > cache = cache.getReconnectedCache();
> > return null;
> > }
> > }));
> > }
> >
Re: Client Cache Behavior after ForcedDisconnectException
Posted by Swapnil Bawaskar <sb...@pivotal.io>.
Hi Avinash,
The testcase you posted is missing createRegionInEachVM(), so I could not
run it.
Can you describe what is the error?
On Mon, Jul 11, 2016 at 7:18 AM, Avinash Dongre <do...@gmail.com>
wrote:
> Hi All,
> I want to understand the Client-Cache Behavior after for some reason
> server is getting reconnected due to ForcedDisconnectException.
>
> 1. Do I need to create client cache again, and Regions ?
>
> I tried to write following Tests but it is failing , Please help.
>
> private void forcedDisconnectAndReconnectEachVM() {
> new ArrayList<>(Arrays.asList(vm0/*, vm1, vm2*/)).
> forEach((VM) -> VM.invoke(new SerializableCallable() {
> @Override
> public Object call() throws Exception {
> GemFireCacheImpl oldCache = (GemFireCacheImpl)
> CacheFactory.getAnyInstance();
> assertNotNull(oldCache);
> InternalDistributedSystem distributedSystem =
> (InternalDistributedSystem) oldCache.getDistributedSystem();
> assertNotNull(distributedSystem);
>
> MembershipManagerHelper.crashDistributedSystem(distributedSystem);
> return null;
> }
> }));
> }
>
> private void updateServerCacheAfterReconnect() {
> new ArrayList<>(Arrays.asList(vm0/*, vm1, vm2*/)).
> forEach((VM) -> VM.invoke(new SerializableCallable() {
> @Override
> public Object call() throws Exception {
> Cache cache = CacheFactory.getAnyInstance();
> cache = cache.getReconnectedCache();
> return null;
> }
> }));
> }
>
> public void testForcedDisconnectException() {
>
> createRegionInEachVM();
>
> ClientCache clientCache = ClientCacheFactory.getAnyInstance();
> ClientRegionFactory<String, String> crf =
> clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
>
> Region<String, String> test_pr_region = crf.create("TEST_PR_REGION");
>
> for (int i = 0; i < 10; i++) {
> test_pr_region.put("Key" + i, "Value" + i);
> }
>
> forcedDisconnectAndReconnectEachVM();
> updateServerCacheAfterReconnect();
> createRegionInEachVM();
>
>
> for (int i = 0; i < 10; i++) {
> final String s = test_pr_region.get("Key" + i);
> assertEquals("Value" + i , s);
> }
> }
>