<https://stackoverflow.com/questions/76801869/test...
# server
j
Copy code
@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@OptIn(ExperimentalCoroutinesApi::class)
class VehicleApiIT {

    companion object {

        @JvmStatic
        @Container
        @ServiceConnection
        private val postgreSQLContainer = PostgreSQLContainer(DockerImageName.parse("postgres:14.7-alpine"))
            .withDatabaseName("vehicle-service")
            .withUsername("vs")
            .withPassword("vs")

        init {
            postgreSQLContainer.start()
        }
    }
...
}
that code does work for Testcontainers and PostgreSQL, so hopefully it'll work for you
e
thank you for your code can you tell me what is the problem with my code in stackoverflow @JasonB
j
no, I don't have a specific answer for you
e
@JasonB I have tried your code it is giving an error
I still dont understand where I am making problem
j
you'll at least need to show your error
e
Copy code
Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@OptIn(ExperimentalCoroutinesApi::class)
class KotlinApplicationTests(@Autowired private val customerRepository: CustomerRepository) {

    companion object {

       @JvmStatic
       @Container
       @ServiceConnection
       private val postgreSQLContainer = PostgreSQLContainer(DockerImageName.parse("postgres:14.7-alpine"))
             .withDatabaseName("customers")
             .withUsername("postgres")
             .withPassword("postgres")

       init {
          postgreSQLContainer.start()
       }
    }




    @Test
    fun contextLoads() {
   runBlocking {

       customerRepository.save(Customer(null, "Hadi"))
       val customers = customerRepository.findAll()
       Assertions.assertNotNull(customers.last().id)
       Assertions.assertEquals(customers.count(), 6)
   }



    }

}
my code
Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
j
as the error says, you need Docker installed on your machine
e
I have installed docker in my machine
j
my suggestion is to search for that error, then - I can't really diagnose your machine
e
@JasonB thank you so much it worked it was docker problem
j
great, glad you got it working!
e
Jason thank you so much I am android developer am going back to backend development with kotlin or java can you suggest what I have to learn with kotlin spring boot
j
I'm afraid that question is far too broad - there are a lot of blogs out there that can help you with specific problems, and just reading the Spring docs is good
e
have you worked with flux
with spring boot
j
I do coroutines with Spring Boot, yes
e
I am getting following exception what do you think problem
Copy code
@Bean
 suspend fun http(customerRepository: CustomerRepository) =
    coRouter {
       GET("customers/")
       ServerResponse.ok().bodyAndAwait(customerRepository.findAll())
    }
}
I have tried with
fun
Copy code
fun http(customerRepository: CustomerRepository) =
    coRouter {
       GET("customers/")
       ServerResponse.ok().bodyAndAwait(customerRepository.findAll())
    }
}
as well
j
I don't use
coRouter
but I don't think you are using it correctly
e
I am following jetbrains tutorial
j
sorry, if you are following the tutorial I'm sure there is plenty of help available
e
Screenshot (566).png
can I ask question
I fixed problem
j
good, glad you fixed it
how far did you get?
e
when I run project I am getting following exception Web server failed to start. Port 8090 was already in use. Action: Identify and stop the process that's listening on port 8090 or configure this application to listen on another port.
j
I would suggest finding the process that is holding on to that port
you likely have your server running somewhere else
e
it is not running on docker right ?
j
the web server is not running in docker, just the DB
e
TCP 0.0.0.0:8090 0.0.0.0:0 LISTENING 12928 TCP [:]8090 [:]0 LISTENING 12928
j
good, seems like you found the process that's using the port
e
what do you think why spring boot taking so much time to run
Screenshot (569).png