MCPcopy Index your code
hub / github.com/cschanck/single-file-java / testMap

Method testMap

src/test/java/org/sfj/ProxyMeTest.java:64–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62 }
63
64 @Test
65 public void testMap() {
66
67 ProxyMe.Server<ConcurrentHashMap<Integer, Integer>>
68 server =
69 new ProxyMe.Server<>(Map.class, new ConcurrentHashMap());
70
71 LinkedBlockingQueue<ProxyMe.Invocation> invocations = new LinkedBlockingQueue<>();
72
73 ProxyMe.Client<Map<Integer, Integer>>
74 client =
75 new ProxyMe.Client<>(Executors.newScheduledThreadPool(1), Map.class, invocations::offer, 1, TimeUnit.SECONDS);
76
77 Map<Integer, Integer> mapProxy = client.clientProxy(Thread.currentThread().getContextClassLoader());
78
79 AtomicBoolean live = new AtomicBoolean(true);
80 Executors.newCachedThreadPool().submit(() -> {
81 for (; live.get(); ) {
82 try {
83 ProxyMe.Invocation p = invocations.poll(1, TimeUnit.SECONDS);
84 if (p != null) {
85 client.complete(server.invoke(p));
86 }
87 } catch (InterruptedException e) {
88 e.printStackTrace();
89 }
90 }
91 });
92
93 for (int i = 0; i < 10; i++) {
94 mapProxy.put(i, i * 10);
95 }
96 for (int i = 0; i < 10; i++) {
97 assertThat(mapProxy.get(i), is(10 * i));
98 }
99 assertThat(mapProxy.size(), is(10));
100
101 live.set(false);
102 }
103
104 @Test
105 public void testTimeout() {

Callers

nothing calls this directly

Calls 8

clientProxyMethod · 0.95
completeMethod · 0.95
invokeMethod · 0.95
getMethod · 0.65
pollMethod · 0.65
putMethod · 0.45
sizeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected