Mee42 / cs509-project

2 stars 0 forks source link

[BUG] Backend Unit Test JDBC Connection Error #69

Closed travis-mann closed 4 months ago

travis-mann commented 4 months ago

Currently, the backend unit tests are failing with a JDBC Connection Error

Commands used to start tests

cd ./backend
mvn clean
mvn test

Error:

[INFO] Running cs509.backend.HTTPTests
2024-04-27T15:11:19.189-04:00  INFO 29288 --- [           main] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [cs509.backend.HTTPTests]: HTTPTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2024-04-27T15:11:19.192-04:00  INFO 29288 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration cs509.backend.BackendApplication for test class cs509.backend.HTTPTests
2024-04-27T15:11:19.218-04:00  INFO 29288 --- [           main] o.s.mock.web.MockServletContext          : Initializing Spring TestDispatcherServlet ''
2024-04-27T15:11:19.218-04:00  INFO 29288 --- [           main] o.s.t.web.servlet.TestDispatcherServlet  : Initializing Servlet ''
2024-04-27T15:11:19.220-04:00  INFO 29288 --- [           main] o.s.t.web.servlet.TestDispatcherServlet  : Completed initialization in 1 ms
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 30.09 s <<< FAILURE! -- in cs509.backend.HTTPTests
[ERROR] cs509.backend.HTTPTests.test -- Time elapsed: 30.08 s <<< ERROR!
jakarta.servlet.ServletException: Request processing failed: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1022)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
        at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:72)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
        at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:165)
        at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
        at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:201)
        at cs509.backend.HTTPTests.test(HTTPTests.java:32)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:84)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:653)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:723)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:754)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:767)
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:825)
        at org.springframework.jdbc.core.simple.DefaultJdbcClient$DefaultStatementSpec$IndexedParamMappedQuerySpec.list(DefaultJdbcClient.java:346)
        at cs509.backend.Repository.FlightRepository.getAllArriveAirports(FlightRepository.java:160)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:351)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:717)
        at cs509.backend.Repository.FlightRepository$$SpringCGLIB$$0.getAllArriveAirports(<generated>)
        at cs509.backend.Service.FlightService.getAllArriveAirports(FlightService.java:110)
        at cs509.backend.Controller.FlightController.getAllArriveAirports(FlightController.java:28)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:261)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:189)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:917)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:829)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
        ... 12 more
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30009ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:696)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:181)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:146)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
        at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:160)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81)
        ... 47 more

[INFO] Running cs509.backend.TestDataClass
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.017 s -- in cs509.backend.TestDataClass
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors: 
[ERROR]   HTTPTests.test:32 » Servlet Request processing failed: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
[INFO]
[ERROR] Tests run: 29, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:52 min
[INFO] Finished at: 2024-04-27T15:11:59-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test (default-test) on project backend:
[ERROR]
[ERROR] Please refer to D:\Programming\CS509\cs509-project\cs509-project\backend\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
ChinhDangg commented 4 months ago

The error was there because Carson's tests need the whole backend application running which required the database and all the data imported. I fixed that to my test style where it used an isolated test container which is already available on GitHub actions.