Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection in the pool closed by the database won't be removed from the available connections #63

Closed
vietj opened this issue Mar 4, 2018 · 3 comments
Milestone

Comments

@vietj
Copy link
Member

vietj commented Mar 4, 2018

No description provided.

@vietj vietj closed this as completed in 836217d Mar 4, 2018
@vietj vietj added this to the 0.6.0 milestone Mar 4, 2018
@mostafa-korkar1
Copy link

at io.vertx.core.impl.future.FutureImpl$2.onFailure(FutureImpl.java:117)
at io.vertx.core.impl.future.FutureImpl$ListenerArray.onFailure(FutureImpl.java:268)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
at io.vertx.core.impl.future.Mapping.onFailure(Mapping.java:45)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23)
at io.vertx.sqlclient.impl.QueryResultBuilder.tryFail(QueryResultBuilder.java:116)
at io.vertx.core.Promise.fail(Promise.java:89)
at io.vertx.core.Promise.handle(Promise.java:53)
at io.vertx.core.Promise.handle(Promise.java:29)
at io.vertx.core.impl.future.FutureImpl$3.onFailure(FutureImpl.java:153)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
at io.vertx.core.impl.future.Composition$1.onFailure(Composition.java:66)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
at io.vertx.core.impl.future.FailedFuture.addListener(FailedFuture.java:98)
at io.vertx.core.impl.future.Composition.onFailure(Composition.java:55)
at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23)
at io.vertx.core.impl.future.PromiseImpl.onFailure(PromiseImpl.java:54)
at io.vertx.core.impl.future.PromiseImpl.handle(PromiseImpl.java:43)
at io.vertx.core.impl.future.PromiseImpl.handle(PromiseImpl.java:23)
at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)
at io.vertx.core.impl.EventLoopContext.lambda$emit$1(EventLoopContext.java:62)
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)

May 09, 2023 11:59:11 PM com.coral.bookstore.service.BookHandler$Companion$buildErrorResponse$1 invoke
SEVERE: buildErrorResponse - Error : io.vertx.core.impl.NoStackTraceThrowable: Pool closed

@mostafa-korkar1
Copy link

my DB Connection class as following:

`
class DBConnection {

private val logger = Logger.getLogger(DBConnection::class.java.name)

fun pgPool(vertx : Vertx): PgPool {
val context: Context = vertx.orCreateContext
val activeProfile : String = context.config().getString("active_profile", "TEST")
logger.info("DBConnection - active Profile : ".plus(activeProfile))
lateinit var config: JsonObject
lateinit var connectOptions : PgConnectOptions
lateinit var poolOptions : PoolOptions
if (activeProfile.equals("DEV")) {
config = vertx.fileSystem().readFileBlocking("DB_Connection.json").toJsonObject()
connectOptions = PgConnectOptions()
.setPort(config.getInteger("port"))
.setHost(config.getString("host"))
.setDatabase(config.getString("database"))
.setUser(config.getString("user"))
.setPassword(config.getString("password"))
// Pool Options
poolOptions = PoolOptions().setMaxSize(config.getInteger("max_pool_size")).setShared(true)
}else {
connectOptions = PgConnectOptions.fromUri(context.config().getString("db.uri"))
.setUser(context.config().getString("db.username"))
.setPassword(context.config().getString("db.password"))
poolOptions = PoolOptions().setMaxSize(context.config().getInteger("max_pool_size")).setShared(true)
}

// Create the pool from the data object
return PgPool.pool(vertx, connectOptions, poolOptions)

}
}
`

@mostafa-korkar1
Copy link

my Test class as following :

`
@testcontainers
@ExtendWith(VertxExtension::class)
class MainVerticleIntegrationTest {

private val logger = Logger.getLogger(MainVerticleIntegrationTest::class.java.name)
private val deploymentOptions: DeploymentOptions = DeploymentOptions()

@beforeeach
fun deploy_verticle(vertx: Vertx, testContext: VertxTestContext) {
val dbUri = postgresqlContainer.jdbcUrl.substringAfter("jdbc:")
deploymentOptions.config = jsonObjectOf(
"db.uri" to dbUri,
"db.username" to DB_USERNAME,
"db.password" to DB_PASSWORD,
"max_pool_size" to 5
)
vertx.deployVerticle(MainVerticle(), deploymentOptions, testContext.succeeding { _ -> testContext.completeNow() })
}

@test
fun test() {
assertThat(postgresqlContainer.isRunning).isTrue
}

@test
@DisplayName("test_return_all_books")
fun test_return_all_books(vertx: Vertx, testContext: VertxTestContext) {

var bookInfoToBeMatched = BookInfo(1, "zxc3", "Test 1", 52)
var client: HttpClient = vertx.createHttpClient()
client.request(HttpMethod.GET, 8090, "localhost", "/books")
  .compose(HttpClientRequest::send)
  .compose(HttpClientResponse::body)
  .onSuccess { body ->
    testContext.verify {
      val bookInfos = toList(body.toJsonArray())
      assertThat(bookInfos).anyMatch { it -> checkingBookMatching(it, bookInfoToBeMatched) }
    }
    testContext.completeNow()
  }
  .onFailure { failure -> testContext.failNow(failure) };

}
companion object {
private const val DB_NAME = "coral_book_store"
private const val DB_USERNAME = "coral"
private const val DB_PASSWORD = "coral"

@Container
private var postgresqlContainer: PostgreSQLContainer<Nothing> = PostgreSQLContainer<Nothing>("postgres:15")
  .apply {
    withDatabaseName(DB_NAME)
    withUsername(DB_USERNAME)
    withPassword(DB_PASSWORD)
  }

}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants