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
The following commit(s) were added to refs/heads/master by this push:
new 12b1bfd Coverage of hobbits and devp2p
new 55da81c Merge pull request #131 from atoulme/coverage_of_io_and_crypto
12b1bfd is described below
commit 12b1bfd4f0e152995be87bcde39462c501be3bfc
Author: Antoine Toulme <[email protected]>
AuthorDate: Sat Jul 18 00:30:18 2020 -0700
Coverage of hobbits and devp2p
---
.../devp2p/v5/internal/DefaultUdpConnectorTest.kt | 2 -
.../tuweni/devp2p/v5/topic/TopicIntegrationTest.kt | 4 +-
.../apache/tuweni/hobbits/HobbitsTransportTest.kt | 28 ++++++++++--
.../org/apache/tuweni/hobbits/MessageTest.kt | 52 +++++++++++++++++++++-
.../apache/tuweni/kademlia/KademliaRoutingTable.kt | 6 ++-
5 files changed, 79 insertions(+), 13 deletions(-)
diff --git
a/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/internal/DefaultUdpConnectorTest.kt
b/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/internal/DefaultUdpConnectorTest.kt
index 9ec2c7f..cfc1db8 100644
---
a/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/internal/DefaultUdpConnectorTest.kt
+++
b/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/internal/DefaultUdpConnectorTest.kt
@@ -34,7 +34,6 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
-import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.extension.ExtendWith
@@ -45,7 +44,6 @@ import java.net.InetSocketAddress
import java.nio.ByteBuffer
@Timeout(10)
-@Disabled
@ObsoleteCoroutinesApi
@ExtendWith(BouncyCastleExtension::class)
@Execution(ExecutionMode.SAME_THREAD)
diff --git
a/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/topic/TopicIntegrationTest.kt
b/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/topic/TopicIntegrationTest.kt
index 22a7f7c..07d5b88 100644
---
a/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/topic/TopicIntegrationTest.kt
+++
b/devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/topic/TopicIntegrationTest.kt
@@ -37,7 +37,6 @@ import java.net.InetAddress
@Timeout(10)
class TopicIntegrationTest : AbstractIntegrationTest() {
- @Disabled("Blocks testing")
@Test
fun advertiseTopicAndRegistrationSuccessful() = runBlocking {
val node1 = createNode(9070)
@@ -57,7 +56,7 @@ class TopicIntegrationTest : AbstractIntegrationTest() {
node2.service.terminate()
}
- @Disabled("Blocks testing")
+ @Disabled
@ExperimentalCoroutinesApi
@Test
fun advertiseTopicAndNeedToWaitWhenTopicQueueIsFull() =
runBlocking(Dispatchers.Unconfined) {
@@ -86,7 +85,6 @@ class TopicIntegrationTest : AbstractIntegrationTest() {
node2.service.terminate()
}
- @Disabled("Blocks testing")
@Test
fun searchTopicReturnListOfNodes() = runBlocking {
val node1 = createNode(9060)
diff --git
a/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/HobbitsTransportTest.kt
b/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/HobbitsTransportTest.kt
index d04b0f0..b4812b4 100644
--- a/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/HobbitsTransportTest.kt
+++ b/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/HobbitsTransportTest.kt
@@ -24,10 +24,11 @@ import org.apache.tuweni.concurrent.coroutines.await
import org.apache.tuweni.junit.VertxExtension
import org.apache.tuweni.junit.VertxInstance
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
-import java.lang.IllegalStateException
+import java.util.concurrent.atomic.AtomicInteger
@ExtendWith(VertxExtension::class)
class HobbitsTransportTest {
@@ -45,8 +46,10 @@ class HobbitsTransportTest {
val server = HobbitsTransport(vertx)
val exception: IllegalStateException = assertThrows {
runBlocking {
- server.sendMessage(Message(protocol = Protocol.RPC, headers =
Bytes.EMPTY, body = Bytes.EMPTY),
- Transport.TCP, "localhost", 9000)
+ server.sendMessage(
+ Message(protocol = Protocol.RPC, headers = Bytes.EMPTY, body =
Bytes.EMPTY),
+ Transport.TCP, "localhost", 9000
+ )
}
}
assertEquals("Server not started", exception.message)
@@ -68,7 +71,7 @@ class HobbitsTransportTest {
val listening = vertx.createNetServer()
listening.connectHandler {
it.handler {
- completion.complete(Bytes.wrapBuffer(it))
+ completion.complete(Bytes.wrapBuffer(it))
}
}.listen(0, "localhost") {
runBlocking {
@@ -81,4 +84,21 @@ class HobbitsTransportTest {
}
}
}
+
+ @Test
+ fun registerEndpoints(@VertxInstance vertx: Vertx) = runBlocking {
+ val server = HobbitsTransport(vertx)
+ val httpPort = AtomicInteger()
+ val tcpPort = AtomicInteger()
+ val wsPort = AtomicInteger()
+ server.createHTTPEndpoint("myhttp", "localhost", port = 0, handler = {},
portUpdateListener = httpPort::set)
+ server.createUDPEndpoint("myudp", "localhost", handler = {}, port = 32009)
+ server.createTCPEndpoint("mytcp", "localhost", port = 0, handler = {},
portUpdateListener = tcpPort::set)
+ server.createWSEndpoint("myws", "localhost", port = 0, handler = {},
portUpdateListener = wsPort::set)
+ server.start()
+ assertNotEquals(0, tcpPort.get())
+ assertNotEquals(0, httpPort.get())
+ assertNotEquals(0, wsPort.get())
+ server.stop()
+ }
}
diff --git a/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/MessageTest.kt
b/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/MessageTest.kt
index 9c1469a..1078b58 100644
--- a/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/MessageTest.kt
+++ b/hobbits/src/test/kotlin/org/apache/tuweni/hobbits/MessageTest.kt
@@ -18,14 +18,19 @@ package org.apache.tuweni.hobbits
import org.apache.tuweni.bytes.Bytes
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertNotNull
+import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertThrows
class MessageTest {
@Test
fun parseMessageRoundtrip() {
- val msg = Message(protocol = Protocol.PING, headers =
Bytes.fromHexString("deadbeef01"),
- body = Bytes.fromHexString("deadbeef02"))
+ val msg = Message(
+ protocol = Protocol.PING, headers = Bytes.fromHexString("deadbeef01"),
+ body = Bytes.fromHexString("deadbeef02")
+ )
val serialized = msg.toBytes()
val read = Message.readMessage(serialized)!!
assertEquals(3, read.version)
@@ -33,4 +38,47 @@ class MessageTest {
assertEquals(Bytes.fromHexString("deadbeef01"), read.headers)
assertEquals(Bytes.fromHexString("deadbeef02"), read.body)
}
+
+ @Test
+ fun invalidProtocol() {
+ assertEquals(Protocol.RPC, Protocol.fromByte(0))
+ assertEquals(Protocol.GOSSIP, Protocol.fromByte(1))
+ assertEquals(Protocol.PING, Protocol.fromByte(2))
+ assertThrows<IllegalArgumentException> { Protocol.fromByte(4) }
+ }
+
+ @Test
+ fun testToString() {
+ val msg = Message(
+ protocol = Protocol.PING, headers = Bytes.fromHexString("deadbeef01"),
+ body = Bytes.fromHexString("deadbeef02")
+ )
+ assertEquals(
+ "EWP 3 PING 5 5\n" +
+ "0xdeadbeef01\n" +
+ "0xdeadbeef02", msg.toString()
+ )
+ }
+
+ @Test
+ fun testSize() {
+ val msg = Message(
+ protocol = Protocol.PING, headers = Bytes.fromHexString("deadbeef01"),
+ body = Bytes.fromHexString("deadbeef02")
+ )
+ assertEquals(26, msg.size()
+ )
+ }
+
+ @Test
+ fun testReadMessage() {
+ val msg = Message(
+ protocol = Protocol.PING, headers = Bytes.fromHexString("deadbeef01"),
+ body = Bytes.fromHexString("deadbeef02")
+ )
+ val serialized = msg.toBytes()
+ assertNull(Message.readMessage(serialized.slice(0, 3)))
+ assertNull(Message.readMessage(serialized.slice(0, 20)))
+ assertNotNull(Message.readMessage(serialized))
+ }
}
diff --git
a/kademlia/src/main/kotlin/org/apache/tuweni/kademlia/KademliaRoutingTable.kt
b/kademlia/src/main/kotlin/org/apache/tuweni/kademlia/KademliaRoutingTable.kt
index 76fb988..b7a1f4c 100644
---
a/kademlia/src/main/kotlin/org/apache/tuweni/kademlia/KademliaRoutingTable.kt
+++
b/kademlia/src/main/kotlin/org/apache/tuweni/kademlia/KademliaRoutingTable.kt
@@ -18,6 +18,7 @@ package org.apache.tuweni.kademlia
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
+import java.util.Collections
import java.util.function.Function
/**
@@ -179,7 +180,8 @@ class KademliaRoutingTable<T>(
fun nearest(targetId: ByteArray, limit: Int): List<T> {
val results = mutableListOf<T>()
for (bucket in buckets) {
- for (node in bucket) {
+ val bucketView = ArrayList(bucket)
+ for (node in bucketView) {
val nodeId = idForNode(node)
results.orderedInsert(node) { a, _ ->
targetId.xorDistCmp(idForNode(a), nodeId) }
if (results.size > limit) {
@@ -244,7 +246,7 @@ class KademliaRoutingTable<T>(
private val maxReplacements: Int
) : List<E> by entries {
- constructor(k: Int, maxReplacements: Int) : this(mutableListOf(), k,
maxReplacements)
+ constructor(k: Int, maxReplacements: Int) :
this(Collections.synchronizedList(mutableListOf()), k, maxReplacements)
// ordered with most recent last
private val replacementCache = mutableListOf<E>()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]