mirror of
https://github.com/corda/corda.git
synced 2025-01-26 06:09:25 +00:00
Merge pull request #451 from corda/mnesbit-fix-flaky-tests
Fixes some charset encoding and timing tests problems on windows
This commit is contained in:
commit
b75913c24a
@ -149,7 +149,7 @@ class AttachmentClassLoaderTests {
|
||||
val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data")))
|
||||
|
||||
val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! })
|
||||
val txt = IOUtils.toString(cl.getResourceAsStream("file1.txt"))
|
||||
val txt = IOUtils.toString(cl.getResourceAsStream("file1.txt"), Charsets.UTF_8.name())
|
||||
assertEquals("some data", txt)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -74,14 +74,14 @@ class IRSDemoTest : IntegrationTestCategory {
|
||||
}
|
||||
|
||||
private fun runTrade(nodeAddr: HostAndPort, fixedRatePayer: Party, floatingRatePayer: Party) {
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"))
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"), Charsets.UTF_8.name())
|
||||
val tradeFile = fileContents.replace("tradeXXX", "trade1")
|
||||
val url = URL("http://$nodeAddr/api/irs/deals")
|
||||
assert(postJson(url, tradeFile))
|
||||
}
|
||||
|
||||
private fun runUploadRates(host: HostAndPort) {
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"), Charsets.UTF_8.name())
|
||||
val url = URL("http://$host/upload/interest-rates")
|
||||
assert(uploadFile(url, fileContents))
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class IRSDemoClientApi(private val hostAndPort: HostAndPort) {
|
||||
private val api = HttpApi.fromHostAndPort(hostAndPort, apiRoot)
|
||||
|
||||
fun runTrade(tradeId: String): Boolean {
|
||||
val fileContents = IOUtils.toString(javaClass.classLoader.getResourceAsStream("example-irs-trade.json"))
|
||||
val fileContents = IOUtils.toString(javaClass.classLoader.getResourceAsStream("example-irs-trade.json"), Charsets.UTF_8.name())
|
||||
val tradeFile = fileContents.replace("tradeXXX", tradeId)
|
||||
return api.postJson("deals", tradeFile)
|
||||
}
|
||||
@ -24,7 +24,7 @@ class IRSDemoClientApi(private val hostAndPort: HostAndPort) {
|
||||
|
||||
// TODO: Add uploading of files to the HTTP API
|
||||
fun runUploadRates() {
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
|
||||
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"), Charsets.UTF_8.name())
|
||||
val url = URL("http://$hostAndPort/upload/interest-rates")
|
||||
assert(uploadFile(url, fileContents))
|
||||
}
|
||||
|
@ -37,5 +37,6 @@ private fun makeRequest(request: Request): Boolean {
|
||||
if (!response.isSuccessful) {
|
||||
println("Could not fulfill HTTP request. Status Code: ${response.code()}. Message: ${response.body().string()}")
|
||||
}
|
||||
response.close()
|
||||
return response.isSuccessful
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user