mirror of
https://github.com/corda/corda.git
synced 2025-06-18 07:08:15 +00:00
Fix unit tests causing problems on windows
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package net.corda.node.utilities.registration
|
||||
|
||||
import com.google.common.net.MediaType
|
||||
import net.corda.core.crypto.CertificateStream
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest
|
||||
@ -50,7 +51,7 @@ class HTTPNetworkRegistrationService(val server: URL) : NetworkRegistrationServi
|
||||
conn.outputStream.write(request.encoded)
|
||||
|
||||
return when (conn.responseCode) {
|
||||
HTTP_OK -> IOUtils.toString(conn.inputStream)
|
||||
HTTP_OK -> IOUtils.toString(conn.inputStream, conn.charset)
|
||||
HTTP_FORBIDDEN -> throw IOException("Client version $clientVersion is forbidden from accessing permissioning server, please upgrade to newer version.")
|
||||
else -> throwUnexpectedResponseCode(conn)
|
||||
}
|
||||
@ -60,5 +61,7 @@ class HTTPNetworkRegistrationService(val server: URL) : NetworkRegistrationServi
|
||||
throw IOException("Unexpected response code ${connection.responseCode} - ${connection.errorMessage}")
|
||||
}
|
||||
|
||||
private val HttpURLConnection.errorMessage: String get() = IOUtils.toString(errorStream)
|
||||
private val HttpURLConnection.charset: String get() = MediaType.parse(getContentType()).charset().or(Charsets.UTF_8).name()
|
||||
|
||||
private val HttpURLConnection.errorMessage: String get() = IOUtils.toString(errorStream, charset)
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
alice = second
|
||||
}
|
||||
network.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
@After
|
||||
@ -197,10 +198,18 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
return response.getOrThrow().node
|
||||
}
|
||||
|
||||
private var lastSerial = Long.MIN_VALUE
|
||||
|
||||
private fun MockNode.registration(addOrRemove: AddOrRemove,
|
||||
serial: Long = System.currentTimeMillis()): ListenableFuture<RegistrationResponse> {
|
||||
serial: Long? = null): ListenableFuture<RegistrationResponse> {
|
||||
val distinctSerial = if (serial == null) {
|
||||
++lastSerial
|
||||
} else {
|
||||
lastSerial = serial
|
||||
serial
|
||||
}
|
||||
val expires = Instant.now() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||
val nodeRegistration = NodeRegistration(info, serial, addOrRemove, expires)
|
||||
val nodeRegistration = NodeRegistration(info, distinctSerial, addOrRemove, expires)
|
||||
val request = RegistrationRequest(nodeRegistration.toWire(services.legalIdentityKey.private), info.address)
|
||||
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
|
||||
network.runNetwork()
|
||||
@ -235,6 +244,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
private fun addNewNodeToNetworkMap(legalName: String): MockNode {
|
||||
val node = network.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
|
||||
network.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
return node
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user