node, integtest: Code style

This commit is contained in:
Andras Slemmer 2016-06-27 10:23:48 +01:00
parent ffa9ad1bc9
commit 429d8aab74
6 changed files with 21 additions and 21 deletions

View File

@ -19,7 +19,7 @@ class APIServerImpl(val node: AbstractNode) : APIServer {
override fun serverTime(): LocalDateTime = LocalDateTime.now(node.services.clock) override fun serverTime(): LocalDateTime = LocalDateTime.now(node.services.clock)
override fun status(): Response { override fun status(): Response {
return if(node.started) { return if (node.started) {
Response.ok("started").build() Response.ok("started").build()
} else { } else {
Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("not started").build() Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("not started").build()

View File

@ -71,7 +71,7 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
// when our process shuts down, but we try in stop() anyway just to be nice. // when our process shuts down, but we try in stop() anyway just to be nice.
private var nodeFileLock: FileLock? = null private var nodeFileLock: FileLock? = null
// Todo: Move to node config file // TODO: Move to node config file
private var webServerPort: Int = p2pAddr.port + 1 private var webServerPort: Int = p2pAddr.port + 1
override fun makeMessagingService(): MessagingService = ArtemisMessagingService(dir, p2pAddr, serverThread) override fun makeMessagingService(): MessagingService = ArtemisMessagingService(dir, p2pAddr, serverThread)

View File

@ -36,8 +36,7 @@ class DataUploadServlet : HttpServlet() {
val iterator = upload.getItemIterator(req) val iterator = upload.getItemIterator(req)
val messages = ArrayList<String>() val messages = ArrayList<String>()
if(!iterator.hasNext()) if (!iterator.hasNext()) {
{
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files") resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files")
return return
} }

View File

@ -31,6 +31,7 @@ class IRSDemoTest {
} }
} }
} }
private fun setupNode(dir: Path, nodeType: String) { private fun setupNode(dir: Path, nodeType: String) {
println("Running setup for $nodeType") println("Running setup for $nodeType")
val args = listOf("--role", "Setup" + nodeType, "--dir", dir.toString()) val args = listOf("--role", "Setup" + nodeType, "--dir", dir.toString())
@ -74,7 +75,7 @@ private fun runDateChange(nodeAddr: HostAndPort) {
} }
private fun stopNode(nodeProc: Process?) { private fun stopNode(nodeProc: Process?) {
if(nodeProc != null) { if (nodeProc != null) {
println("Stopping node") println("Stopping node")
assertAliveAndKill(nodeProc) assertAliveAndKill(nodeProc)
} }

View File

@ -47,7 +47,7 @@ private fun waitForNodeStartup(nodeAddr: HostAndPort) {
"IOException: ${e.toString()}" "IOException: ${e.toString()}"
} }
if(retries > 25) { if (retries > 25) {
throw NodeDidNotStartException("The node did not start: " + err) throw NodeDidNotStartException("The node did not start: " + err)
} }
} while (respCode != 200) } while (respCode != 200)

View File

@ -147,7 +147,7 @@ private fun runDateChange(demoArgs: DemoArgs, options: OptionSet): Int {
"http://localhost:" + (Node.DEFAULT_PORT + 1) "http://localhost:" + (Node.DEFAULT_PORT + 1)
} }
if(!changeDate(dateStr, host)) { if (!changeDate(dateStr, host)) {
return 1 return 1
} }
} else { } else {
@ -161,7 +161,7 @@ private fun runDateChange(demoArgs: DemoArgs, options: OptionSet): Int {
private fun runNode(role: IRSDemoRole, demoArgs: DemoArgs, options: OptionSet): Int { private fun runNode(role: IRSDemoRole, demoArgs: DemoArgs, options: OptionSet): Int {
// If these directory and identity file arguments aren't specified then we can assume a default setup and // If these directory and identity file arguments aren't specified then we can assume a default setup and
// create everything that is needed without needing to run setup. // create everything that is needed without needing to run setup.
if(!options.has(demoArgs.dirArg) && !options.has(demoArgs.fakeTradeWithIdentityFile)) { if (!options.has(demoArgs.dirArg) && !options.has(demoArgs.fakeTradeWithIdentityFile)) {
createNodeConfig(createNodeAParams()); createNodeConfig(createNodeAParams());
createNodeConfig(createNodeBParams()); createNodeConfig(createNodeBParams());
} }
@ -201,7 +201,7 @@ private fun setup(params: NodeParams): Int {
private fun changeDate(date: String, host: String) : Boolean { private fun changeDate(date: String, host: String) : Boolean {
println("Changing date to " + date) println("Changing date to " + date)
val url = URL(host + "/api/irs/demodate") val url = URL(host + "/api/irs/demodate")
if(putJson(url, "\"" + date + "\"")) { if (putJson(url, "\"" + date + "\"")) {
println("Date changed") println("Date changed")
return true return true
} else { } else {
@ -215,7 +215,7 @@ private fun uploadTrade(tradeId: String, host: String) : Boolean {
val fileContents = IOUtils.toString(NodeParams::class.java.getResourceAsStream("example-irs-trade.json")) val fileContents = IOUtils.toString(NodeParams::class.java.getResourceAsStream("example-irs-trade.json"))
val tradeFile = fileContents.replace("tradeXXX", tradeId) val tradeFile = fileContents.replace("tradeXXX", tradeId)
val url = URL(host + "/api/irs/deals") val url = URL(host + "/api/irs/deals")
if(postJson(url, tradeFile)) { if (postJson(url, tradeFile)) {
println("Trade sent") println("Trade sent")
return true return true
} else { } else {
@ -240,9 +240,9 @@ private fun configureNodeParams(role: IRSDemoRole, args: DemoArgs, options: Opti
if (options.has(args.networkAddressArg)) { if (options.has(args.networkAddressArg)) {
nodeParams.address = HostAndPort.fromString(options.valueOf(args.networkAddressArg)).withDefaultPort(Node.DEFAULT_PORT) nodeParams.address = HostAndPort.fromString(options.valueOf(args.networkAddressArg)).withDefaultPort(Node.DEFAULT_PORT)
} }
if(options.has(args.apiPort)) { if (options.has(args.apiPort)) {
nodeParams.apiPort = options.valueOf(args.apiPort) nodeParams.apiPort = options.valueOf(args.apiPort)
} else if(options.has(args.networkAddressArg)) { } else if (options.has(args.networkAddressArg)) {
nodeParams.apiPort = nodeParams.address.port + 1 nodeParams.apiPort = nodeParams.address.port + 1
} }
@ -261,7 +261,7 @@ private fun configureNodeParams(role: IRSDemoRole, args: DemoArgs, options: Opti
return nodeParams return nodeParams
} }
private fun runNode(nodeParams: NodeParams) : Unit { private fun runNode(nodeParams: NodeParams): Unit {
val networkMap = createRecipient(nodeParams.mapAddress) val networkMap = createRecipient(nodeParams.mapAddress)
val destinations = nodeParams.tradeWithAddrs.map({ val destinations = nodeParams.tradeWithAddrs.map({
createRecipient(it) createRecipient(it)
@ -273,7 +273,7 @@ private fun runNode(nodeParams: NodeParams) : Unit {
UpdateBusinessDayProtocol.Handler.register(node) UpdateBusinessDayProtocol.Handler.register(node)
ExitServerProtocol.Handler.register(node) ExitServerProtocol.Handler.register(node)
if(nodeParams.uploadRates) { if (nodeParams.uploadRates) {
runUploadRates(HostAndPort.fromString("localhost:${nodeParams.apiPort}")) runUploadRates(HostAndPort.fromString("localhost:${nodeParams.apiPort}"))
} }
@ -335,7 +335,7 @@ private fun runUploadRates(host: HostAndPort) {
timer = fixedRateTimer("upload-rates", false, 0, 5000, { timer = fixedRateTimer("upload-rates", false, 0, 5000, {
try { try {
val url = URL("http://${host.toString()}/upload/interest-rates") val url = URL("http://${host.toString()}/upload/interest-rates")
if(uploadFile(url, fileContents)) { if (uploadFile(url, fileContents)) {
timer!!.cancel() timer!!.cancel()
println("Rates uploaded successfully") println("Rates uploaded successfully")
} else { } else {
@ -450,7 +450,7 @@ private fun createNodeConfig(params: NodeParams) : NodeConfiguration {
val configFile = params.dir.resolve("config").toFile() val configFile = params.dir.resolve("config").toFile()
val config = loadConfigFile(configFile, params.defaultLegalName) val config = loadConfigFile(configFile, params.defaultLegalName)
if(!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) { if (!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) {
createIdentities(params, config) createIdentities(params, config)
} }
@ -458,11 +458,11 @@ private fun createNodeConfig(params: NodeParams) : NodeConfiguration {
} }
private fun getNodeConfig(params: NodeParams): NodeConfiguration { private fun getNodeConfig(params: NodeParams): NodeConfiguration {
if(!Files.exists(params.dir)) { if (!Files.exists(params.dir)) {
throw NotSetupException("Missing config directory. Please run node setup before running the node") throw NotSetupException("Missing config directory. Please run node setup before running the node")
} }
if(!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) { if (!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) {
throw NotSetupException("Missing identity file. Please run node setup before running the node") throw NotSetupException("Missing identity file. Please run node setup before running the node")
} }
@ -471,7 +471,7 @@ private fun getNodeConfig(params: NodeParams): NodeConfiguration {
} }
private fun getRoleDir(role: IRSDemoRole) : Path { private fun getRoleDir(role: IRSDemoRole) : Path {
when(role) { when (role) {
IRSDemoRole.NodeA -> return Paths.get("nodeA") IRSDemoRole.NodeA -> return Paths.get("nodeA")
IRSDemoRole.NodeB -> return Paths.get("nodeB") IRSDemoRole.NodeB -> return Paths.get("nodeB")
else -> { else -> {