@Test public void testValues() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Collection<String> values = map.values(); assertEquals(3, values.size()); assertTrue(values.contains("val1")); assertTrue(values.contains("val2")); assertTrue(values.contains("val3")); }
assertTrue(map.removeIfPresent("foo", "there")); assertNull(map.put("foo", "there")); assertFalse(map.replaceIfPresent("missing", "nope", "something")); assertTrue(map.replaceIfPresent("foo", "there", "something"));
@Test public void testKeys() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Set<String> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains("foo1")); assertTrue(keys.contains("foo2")); assertTrue(keys.contains("foo3")); }
assertTrue(map.removeIfPresent("foo", "there")); assertNull(map.put("foo", "there")); assertFalse(map.replaceIfPresent("missing", "nope", "something")); assertTrue(map.replaceIfPresent("foo", "there", "something"));
@Test public void testValuesCopied() { LocalMap<String, JsonObject> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put("key1", json1); map.put("key2", json2); map.put("key3", json3); assertEquals(3, map.size()); Collection<JsonObject> values = map.values(); assertEquals(3, values.size()); assertTrue(values.contains(json1)); assertTrue(values.contains(json2)); assertTrue(values.contains(json3)); // copied assertFalse(containsExact(values, json1)); assertFalse(containsExact(values, json2)); assertFalse(containsExact(values, json3)); }
@Test public void testKeysCopied() { LocalMap<JsonObject, String> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put(json1, "val1"); map.put(json2, "val2"); map.put(json3, "val3"); assertEquals(3, map.size()); Set<JsonObject> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains(json1)); assertTrue(keys.contains(json2)); assertTrue(keys.contains(json3)); // copied assertFalse(containsExact(keys, json1)); assertFalse(containsExact(keys, json2)); assertFalse(containsExact(keys, json3)); }
private void testMapOperationResult(BiFunction<LocalMap<String, ShareableObject>, String, ShareableObject> operation) { final String key = "key"; final ShareableObject value = new ShareableObject("some test data"); final LocalMap<String, ShareableObject> map = vertx.sharedData().getLocalMap("foo"); assertNull(map.put(key, value)); final ShareableObject result = operation.apply(map, key); assertEquals(value, result); assertNotSame(value, result); }
map.put(key, d); assertEquals(d, map.get(key)); map.put(key, f); assertEquals(f, map.get(key)); map.put(key, b); assertEquals(b, map.get(key)); map.put(key, s); assertEquals(s, map.get(key)); map.put(key, i); assertEquals(i, map.get(key)); map.put(key, l); assertEquals(l, map.get(key)); map.put(key, true); assertTrue((Boolean)map.get(key)); map.put(key, false); assertFalse((Boolean) map.get(key)); map.put(key, c); assertEquals(c, map.get(key)); map.put(key, buff); Buffer got1 = (Buffer)map.get(key);
@Test public void deleteElementOnComputeFunctionReturningNull() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); // put an initial value map.put("hello", "world"); // retuning null we should remove the entry map.computeIfPresent("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // Same for LocalMap#compute and LocalMap#compute map.compute("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // put a value one more time map.put("hello", "world"); map.merge("hello", "world!!!!!!", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); map.computeIfAbsent("hello", key -> null); assertFalse(map.containsKey("hello")); }
@Override public void put(Session session, Handler<AsyncResult<Void>> resultHandler) { final AbstractSession oldSession = (AbstractSession) localMap.get(session.id()); final AbstractSession newSession = (AbstractSession) session; if (oldSession != null) { // there was already some stored data in this case we need to validate versions if (oldSession.version() != newSession.version()) { resultHandler.handle(Future.failedFuture("Version mismatch")); return; } } newSession.incrementVersion(); localMap.put(session.id(), session); resultHandler.handle(Future.succeededFuture()); }
@Test public void testKeys() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Set<String> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains("foo1")); assertTrue(keys.contains("foo2")); assertTrue(keys.contains("foo3")); }
@Test public void testValues() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Collection<String> values = map.values(); assertEquals(3, values.size()); assertTrue(values.contains("val1")); assertTrue(values.contains("val2")); assertTrue(values.contains("val3")); }
@Test public void testKeysCopied() { LocalMap<JsonObject, String> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put(json1, "val1"); map.put(json2, "val2"); map.put(json3, "val3"); assertEquals(3, map.size()); Set<JsonObject> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains(json1)); assertTrue(keys.contains(json2)); assertTrue(keys.contains(json3)); // copied assertFalse(containsExact(keys, json1)); assertFalse(containsExact(keys, json2)); assertFalse(containsExact(keys, json3)); }
@Test public void testValuesCopied() { LocalMap<String, JsonObject> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put("key1", json1); map.put("key2", json2); map.put("key3", json3); assertEquals(3, map.size()); Collection<JsonObject> values = map.values(); assertEquals(3, values.size()); assertTrue(values.contains(json1)); assertTrue(values.contains(json2)); assertTrue(values.contains(json3)); // copied assertFalse(containsExact(values, json1)); assertFalse(containsExact(values, json2)); assertFalse(containsExact(values, json3)); }
DataSourceHolder(VertxInternal vertx, JsonObject config, LocalMap<String, DataSourceHolder> map, String name) { this.config = config; this.map = map; this.vertx = vertx; this.name = name; map.put(name, this); }
private void testMapOperationResult(BiFunction<LocalMap<String, ShareableObject>, String, ShareableObject> operation) { final String key = "key"; final ShareableObject value = new ShareableObject("some test data"); final LocalMap<String, ShareableObject> map = vertx.sharedData().getLocalMap("foo"); assertNull(map.put(key, value)); final ShareableObject result = operation.apply(map, key); assertEquals(value, result); assertNotSame(value, result); }
map.put(key, d); assertEquals(d, map.get(key)); map.put(key, f); assertEquals(f, map.get(key)); map.put(key, b); assertEquals(b, map.get(key)); map.put(key, s); assertEquals(s, map.get(key)); map.put(key, i); assertEquals(i, map.get(key)); map.put(key, l); assertEquals(l, map.get(key)); map.put(key, true); assertTrue((Boolean)map.get(key)); map.put(key, false); assertFalse((Boolean) map.get(key)); map.put(key, c); assertEquals(c, map.get(key)); map.put(key, buff); Buffer got1 = (Buffer)map.get(key);
@Test public void deleteElementOnComputeFunctionReturningNull() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); // put an initial value map.put("hello", "world"); // retuning null we should remove the entry map.computeIfPresent("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // Same for LocalMap#compute and LocalMap#compute map.compute("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // put a value one more time map.put("hello", "world"); map.merge("hello", "world!!!!!!", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); map.computeIfAbsent("hello", key -> null); assertFalse(map.containsKey("hello")); }
/** * Configures the STOMP server to act as a bridge with the Vert.x event bus. * * @param options the configuration options * @return the current {@link StompServerHandler}. * @see Vertx#eventBus() */ @Override public synchronized StompServerHandler bridge(BridgeOptions options) { destinations.put(Destination.bridge(vertx, options), ""); return this; }
private Integer currentID(String k) { Integer currentID=0; LocalMap<String, Integer> seq = seq(); if(!seq.keySet().contains(k)) { seq.put(k, 0); } currentID = seq.get(k); return currentID; } private void incrementID(String k) {