| 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() { |