-
Notifications
You must be signed in to change notification settings - Fork 6
/
HopBetweenCaches.java
executable file
·52 lines (39 loc) · 1.65 KB
/
HopBetweenCaches.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.benstopford.coherence.bootstrap.morecomplex;
import com.benstopford.coherence.bootstrap.structures.framework.cluster.ClusterRunner;
import com.tangosol.net.NamedCache;
import com.tangosol.util.InvocableMap;
import com.tangosol.util.processor.AbstractProcessor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.Serializable;
import static junit.framework.Assert.assertEquals;
/**
* BTS, 20-Feb-2008
*/
public class HopBetweenCaches extends ClusterRunner implements Serializable {
@Test
public void shouldBeAbleToAcceessDifferentCacheFromAnEntryProcessorIfTheyAreInDifferentCacheServices() {
//*****NB - this is only safe to do if the two caches are in different cache services*****
//*****NB - note that it may work using a single cache service with multiple threads but there is the potential for deadlock*****
NamedCache cache1 = getCache("config/basic-cache-on-different-cache-service.xml", "cache1");
NamedCache cache2 = getBasicCache("cache2");
cache1.invoke("Key", new PutInAnotherCacheEP());
assertEquals("Entry Processors rock!!", cache2.get("Key2"));
}
private class PutInAnotherCacheEP extends AbstractProcessor {
public Object process(InvocableMap.Entry entry) {
NamedCache cache2 = getBasicCache("cache2");
cache2.put("Key2", "Entry Processors rock!!");
return null;
}
}
@Before
public void setUp() throws Exception {
super.setUp();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}