commit a85bd9f48ae45cb8e2965294fea9c372762c5d0c
parent f11653ded54a401c2a64538dd8a078b99e728dd6
Author: MS <ms@taler.net>
Date: Fri, 15 Jul 2022 15:19:37 +0200
sandbox: avoid parallelism
Diffstat:
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -481,8 +481,6 @@ object BankAccountReportsTable : IntIdTable() {
val bankAccount = reference("bankAccount", BankAccountsTable)
}
-
-
fun dbDropTables(dbConnectionString: String) {
Database.connect(dbConnectionString)
transaction {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -27,11 +27,14 @@ import io.ktor.request.*
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.util.AttributeKey
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
import org.jetbrains.exposed.exceptions.ExposedSQLException
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
+import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction
import org.w3c.dom.Document
import tech.libeufin.util.*
@@ -44,6 +47,7 @@ import tech.libeufin.util.ebics_s001.UserSignatureData
import java.math.BigDecimal
import java.security.interfaces.RSAPrivateCrtKey
import java.security.interfaces.RSAPublicKey
+import java.sql.Connection
import java.util.*
import java.util.zip.DeflaterInputStream
import java.util.zip.InflaterInputStream
@@ -697,6 +701,16 @@ private fun handleCct(paymentRequest: String) {
logger.debug("Pain.001: $paymentRequest")
val parseResult = parsePain001(paymentRequest)
transaction {
+ val maybeExist = BankAccountTransactionEntity.find {
+ BankAccountTransactionsTable.pmtInfId eq parseResult.pmtInfId
+ }.firstOrNull()
+ if (maybeExist != null) {
+ logger.info(
+ "Nexus submitted twice the PAIN: ${maybeExist.pmtInfId}. Not taking any action." +
+ " Sandbox gave it this reference: ${maybeExist.accountServicerReference}"
+ )
+ return@transaction
+ }
try {
val bankAccount = getBankAccountFromIban(parseResult.debtorIban)
if (parseResult.currency != bankAccount.demoBank.currency) throw EbicsRequestError(
@@ -1002,7 +1016,7 @@ private fun makePartnerInfo(subscriber: EbicsSubscriberEntity): EbicsTypes.Partn
this.value = bankAccount.iban
}
)
- this.currency = "EUR"
+ this.currency = bankAccount.demoBank.currency
this.description = "Ordinary Bank Account"
this.bankCodeList = listOf(
EbicsTypes.GeneralBankCode().apply {
@@ -1265,7 +1279,10 @@ private fun handleEbicsUploadTransactionTransmission(requestContext: RequestCont
}
}
if (getOrderTypeFromTransactionId(requestTransactionID) == "CCT") {
- logger.debug("Attempting a payment.")
+ logger.debug(
+ "Attempting a payment in thread (name/id): " +
+ "${Thread.currentThread().name}/${Thread.currentThread().id}"
+ )
handleCct(unzippedData.toString(Charsets.UTF_8))
}
return EbicsResponse.createForUploadTransferPhase(
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -58,6 +58,7 @@ import io.ktor.application.*
import io.ktor.features.*
import io.ktor.http.*
import io.ktor.jackson.*
+import io.ktor.network.sockets.*
import io.ktor.request.*
import io.ktor.response.*
import io.ktor.routing.*
@@ -65,7 +66,10 @@ import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.util.*
import io.ktor.util.date.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
import kotlinx.coroutines.newSingleThreadContext
+import kotlinx.coroutines.withContext
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
@@ -951,7 +955,6 @@ val sandboxApp: Application.() -> Unit = {
}
call.respond(EbicsHostsResponse(ebicsHosts))
}
-
// Process one EBICS request
post("/ebicsweb") {
try {
@@ -1600,6 +1603,10 @@ fun serverMain(port: Int) {
this.host = "[::1]"
}
module(sandboxApp)
+ },
+ configure = {
+ workerGroupSize = 1
+ callGroupSize = 1
}
)
logger.info("LibEuFin Sandbox running on port $port")