You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2020/06/06 22:57:06 UTC

[incubator-tuweni] branch master updated (7afe4d2 -> 6562aa5)

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git.


    from 7afe4d2  completing EthController, adding containsKey to KV stores
     new e00bc15  fix kotlin warning
     new 6562aa5  add tests for containsKey, make sure it's well supported

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/tuweni/kv/EntityManagerKeyValueStore.kt | 11 +---
 .../kotlin/org/apache/tuweni/kv/KeyValueStore.kt   |  2 +-
 .../org/apache/tuweni/kv/KeyValueStoreTest.java    |  7 +++
 .../org/apache/tuweni/kv/KeyValueStoreSpec.kt      | 64 ++++++++++++++++++++++
 .../org/apache/tuweni/les/LESSubProtocolHandler.kt |  2 +-
 5 files changed, 74 insertions(+), 12 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org


[incubator-tuweni] 02/02: add tests for containsKey, make sure it's well supported

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit 6562aa545a4dfc24da2f6c33ea25e43b23350493
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Jun 6 15:56:50 2020 -0700

    add tests for containsKey, make sure it's well supported
---
 .../apache/tuweni/kv/EntityManagerKeyValueStore.kt | 11 +---
 .../kotlin/org/apache/tuweni/kv/KeyValueStore.kt   |  2 +-
 .../org/apache/tuweni/kv/KeyValueStoreTest.java    |  7 +++
 .../org/apache/tuweni/kv/KeyValueStoreSpec.kt      | 64 ++++++++++++++++++++++
 4 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/kv/src/main/kotlin/org/apache/tuweni/kv/EntityManagerKeyValueStore.kt b/kv/src/main/kotlin/org/apache/tuweni/kv/EntityManagerKeyValueStore.kt
index ab66f37..a0ce034 100644
--- a/kv/src/main/kotlin/org/apache/tuweni/kv/EntityManagerKeyValueStore.kt
+++ b/kv/src/main/kotlin/org/apache/tuweni/kv/EntityManagerKeyValueStore.kt
@@ -50,16 +50,7 @@ class EntityManagerKeyValueStore<K, V>
     ) = EntityManagerKeyValueStore(entityManagerProvider::get, entityClass, idAccessor::apply)
   }
 
-  override suspend fun containsKey(key: K): Boolean {
-    val em = entityManagerProvider()
-    em.transaction.begin()
-    try {
-      return em.contains(key)
-    } finally {
-      em.transaction.commit()
-      em.close()
-    }
-  }
+  override suspend fun containsKey(key: K): Boolean = get(key) != null
 
   override suspend fun get(key: K): V? {
     val em = entityManagerProvider()
diff --git a/kv/src/main/kotlin/org/apache/tuweni/kv/KeyValueStore.kt b/kv/src/main/kotlin/org/apache/tuweni/kv/KeyValueStore.kt
index 5aaab72..ff2fff9 100644
--- a/kv/src/main/kotlin/org/apache/tuweni/kv/KeyValueStore.kt
+++ b/kv/src/main/kotlin/org/apache/tuweni/kv/KeyValueStore.kt
@@ -42,7 +42,7 @@ interface KeyValueStore<K, V> : Closeable, CoroutineScope {
    * @param key The key for the content.
    * @return An [AsyncResult] that will complete with a boolean result.
    */
-  suspend fun containsKeyAsync(key: K): AsyncResult<Boolean> = asyncResult { containsKey(key) }
+  fun containsKeyAsync(key: K): AsyncResult<Boolean> = asyncResult { containsKey(key) }
 
   /**
    * Retrieves data from the store.
diff --git a/kv/src/test/java/org/apache/tuweni/kv/KeyValueStoreTest.java b/kv/src/test/java/org/apache/tuweni/kv/KeyValueStoreTest.java
index 8f8ec44..8163526 100644
--- a/kv/src/test/java/org/apache/tuweni/kv/KeyValueStoreTest.java
+++ b/kv/src/test/java/org/apache/tuweni/kv/KeyValueStoreTest.java
@@ -12,6 +12,8 @@
  */
 package org.apache.tuweni.kv;
 
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -44,6 +46,7 @@ class KeyValueStoreTest {
     KeyValueStore<Bytes, Bytes> store = MapKeyValueStore.open(map);
     AsyncCompletion completion = store.putAsync(Bytes.of(123), Bytes.of(10, 12, 13));
     completion.join();
+    assertTrue(store.containsKeyAsync(Bytes.of(123)).get());
     Bytes value = store.getAsync(Bytes.of(123)).get();
     assertNotNull(value);
     assertEquals(Bytes.of(10, 12, 13), value);
@@ -56,6 +59,7 @@ class KeyValueStoreTest {
         .open(tmpDir.resolve("mapdb"), bytesIdentityFn, bytesIdentityFn, bytesIdentityFn, bytesIdentityFn)) {
       AsyncCompletion completion = store.putAsync(Bytes.of(123), Bytes.of(10, 12, 13));
       completion.join();
+      assertTrue(store.containsKeyAsync(Bytes.of(123)).get());
       Bytes value = store.getAsync(Bytes.of(123)).get();
       assertNotNull(value);
       assertEquals(Bytes.of(10, 12, 13), value);
@@ -70,6 +74,7 @@ class KeyValueStoreTest {
         .open(store, Base64::encode, Base64::decode, Base64::encode, (key, value) -> Base64.decode(value))) {
       AsyncCompletion completion = proxy.putAsync(Base64.encode(Bytes.of(123)), Base64.encode(Bytes.of(10, 12, 13)));
       completion.join();
+      assertTrue(store.containsKeyAsync(Bytes.of(123)).get());
       String value = proxy.getAsync(Base64.encode(Bytes.of(123))).get();
       assertNotNull(value);
       assertEquals(Base64.encode(Bytes.of(10, 12, 13)), value);
@@ -83,6 +88,7 @@ class KeyValueStoreTest {
     try (KeyValueStore<Bytes, Bytes> store = MapDBKeyValueStore.open(tmpDir.resolve("mapdbdirect"))) {
       AsyncCompletion completion = store.putAsync(Bytes.of(123), Bytes.of(10, 12, 13));
       completion.join();
+      assertTrue(store.containsKeyAsync(Bytes.of(123)).get());
       Bytes value = store.getAsync(Bytes.of(123)).get();
       assertNotNull(value);
       assertEquals(Bytes.of(10, 12, 13), value);
@@ -94,6 +100,7 @@ class KeyValueStoreTest {
     Map<Bytes, Bytes> map = new HashMap<>();
     KeyValueStore<Bytes, Bytes> store = MapKeyValueStore.open(map);
     assertNull(store.getAsync(Bytes.of(123)).get());
+    assertFalse(store.containsKeyAsync(Bytes.of(123)).get());
   }
 
   @Test
diff --git a/kv/src/test/kotlin/org/apache/tuweni/kv/KeyValueStoreSpec.kt b/kv/src/test/kotlin/org/apache/tuweni/kv/KeyValueStoreSpec.kt
index 6a05b3c..e2a3ab5 100644
--- a/kv/src/test/kotlin/org/apache/tuweni/kv/KeyValueStoreSpec.kt
+++ b/kv/src/test/kotlin/org/apache/tuweni/kv/KeyValueStoreSpec.kt
@@ -64,6 +64,14 @@ object KeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should return null when no value is present") {
       runBlocking {
         kv.get(Bytes.wrap("foofoobar".toByteArray())).should.be.`null`
@@ -110,6 +118,14 @@ object InfinispanKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should return null when no value is present") {
       runBlocking {
         kv.get(Bytes.wrap("foofoobar".toByteArray())).should.be.`null`
@@ -154,6 +170,14 @@ object MapDBKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should return null when no value is present") {
       runBlocking {
         kv.get(Bytes.wrap("foofoobar".toByteArray())).should.be.`null`
@@ -225,6 +249,14 @@ object LevelDBKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should return null when no value is present") {
       runBlocking {
         kv.get(Bytes.wrap("foofoobar".toByteArray())).should.be.`null`
@@ -289,6 +321,14 @@ object RocksDBKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should return null when no value is present") {
       runBlocking {
         kv.get(Bytes.wrap("foofoobar".toByteArray())).should.be.`null`
@@ -371,6 +411,14 @@ object SQLKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put(foobar, foo)
+        kv.containsKey(foobar).should.be.`true`
+        kv.containsKey(bar).should.be.`false`
+      }
+    }
+
     it("should allow to update values") {
       runBlocking {
         kv.put(foobar, foo)
@@ -446,6 +494,14 @@ object EntityManagerKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        kv.put("foo", Store("foo", "bar"))
+        kv.containsKey("foo").should.be.`true`
+        kv.containsKey("foobar").should.be.`false`
+      }
+    }
+
     it("should allow to update values") {
       runBlocking {
         kv.put("foo", Store("foo", "bar"))
@@ -510,6 +566,14 @@ object ProxyKeyValueStoreSpec : Spek({
       }
     }
 
+    it("should allow to see if a key is present") {
+      runBlocking {
+        proxy.put(foo, bar)
+        proxy.containsKey(foo).should.be.`true`
+        proxy.containsKey(foobar).should.be.`false`
+      }
+    }
+
     it("should allow to update values") {
       runBlocking {
         proxy.put(foo, bar)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org


[incubator-tuweni] 01/02: fix kotlin warning

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit e00bc1535bb1a9f73df1e1b3e32e863e61660280
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Jun 6 15:56:34 2020 -0700

    fix kotlin warning
---
 les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt b/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
index 3a7c0c9..7a538a3 100644
--- a/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
+++ b/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
@@ -165,7 +165,7 @@ internal class LESSubProtocolHandler(
 
   override fun handleNewPeerConnection(connectionId: String): AsyncCompletion {
     return asyncCompletion {
-        val head = repo.retrieveChainHead()!!
+        val head = repo.retrieveChainHead()
         val genesis = repo.retrieveGenesisBlock()
         val headTd = head.getHeader().getDifficulty()
         val headHash = head.getHeader().getHash()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org