程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了HikariPool-1 - 无法从 mockito 中的数据源获取连接大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决HikariPool-1 - 无法从 mockito 中的数据源获取连接?

开发过程中遇到HikariPool-1 - 无法从 mockito 中的数据源获取连接的问题如何解决?下面主要结合日常开发的经验,给出你关于HikariPool-1 - 无法从 mockito 中的数据源获取连接的解决方法建议,希望对你解决HikariPool-1 - 无法从 mockito 中的数据源获取连接有所启发或帮助;

我正在使用 mockito 执行单元测试以使用 HikarIDatasource 返回数据源, 但通知您无法连接到网络。 我知道作为一个模拟,没有必要点击正确的 URL

07:24:50.913 [main] DEBUG com.zaxxer.hikari.HikariConfig - Driver class Oracle.jdbc.driver.OracleDriver found in Thread context class loader sun.misc.Launcher$AppClassLoader@7106e68e
07:24:50.982 [main] WARN com.zaxxer.hikari.HikariConfig - HikariPool-1 - maxlifetime is less than 30000ms,setTing to default 1800000ms.
07:24:50.982 [main] WARN com.zaxxer.hikari.HikariConfig - HikariPool-1 - IDleTimeout has been set but has no effect because the pool is operaTing as a fixed size pool.
07:24:50.982 [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
07:24:50.987 [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitsql...............none
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestquery.............none
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............20000
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - datasource......................none
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - datasourceClassname.............none
07:24:50.988 [main] DEBUG com.zaxxer.hikari.HikariConfig - datasourceJNDI..................none
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - datasourcePropertIEs............{password=<masked>}
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassname................."Oracle.jdbc.driver.OracleDriver"
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - exceptionOverrIDeClassname......none
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthcheckPropertIEs...........{}
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthcheckRegistry.............none
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - IDleTimeout.....................10000
07:24:50.989 [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQuerIEs..........false
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:Oracle:thin:@192.168.55.147:1522:swd126
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - maxlifetime.....................1800000
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIDle.....................10
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - poolname........................"HikariPool-1"
07:24:50.990 [main] DEBUG com.zaxxer.hikari.HikariConfig - Readonly........................false
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - scheR_780_11845@a..........................none
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionisolation............default
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"teste"
07:24:50.991 [main] DEBUG com.zaxxer.hikari.HikariConfig - valIDationTimeout...............5000
07:24:50.992 [main] INFO com.zaxxer.hikari.HikarIDatasource - HikariPool-1 - StarTing...
07:24:50.998 [main] WARN com.zaxxer.hikari.util.DriverDatasource - Registered driver with driverClassname=Oracle.jdbc.driver.OracleDriver was not found,trying direct instantiation.
07:24:50.999 [main] DEBUG com.zaxxer.hikari.util.DriverDatasource - Driver class Oracle.jdbc.driver.OracleDriver found in Thread context class loader sun.misc.Launcher$AppClassLoader@7106e68e
07:24:54.084 [main] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Failed to create/setup connection: IO Error: The Network Adapter Could not establish the connection
07:24:54.086 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - CAnnot acquire connection from data source
java.sql.sqlRecoverableException: IO Error: The Network Adapter Could not establish the connection

Caused by: Oracle.net.ns.NetException: The Network Adapter Could not establish the connection
    at Oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:445)
    at Oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
    at Oracle.net.ns.nsprotocol.establishConnection(nsprotocol.java:594)
    at Oracle.net.ns.nsprotocol.connect(nsprotocol.java:229)
    at Oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
    at Oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
    ... 78 common frames omitted
 @Component
        public class ConfigDatasource {
        
            @autowired
            private PropertIEs propertIEs;
            public Datasource getDatasource(String url,String username,String password) {
                Datasource datasource = null;
                try {
                    HikariConfig ds = new HikariConfig();
                    ds.setJdbcUrl(url);
                    ds.setUsername(userName);
                    ds.setpassword(password);
                    ds.setDriverClassname(propertIEs.getDriveClassname());
                    ds.setConnectionTimeout(propertIEs.getConnectionTimeout());
                    ds.setMinimumIDle(propertIEs.getMinimumIDle());
                    ds.setMaximumPoolSize(propertIEs.getMaximumPoolSize());
                    ds.setIDleTimeout(propertIEs.getIDleTimeout());
                    ds.setMaxlifetime(propertIEs.getMaxlifetime());
                    datasource = new HikarIDatasource(ds);
                } catch (Exception E) {
                    System.err.println("Error connecTing to the database: " + e.getmessage());
                }
                return datasource;
            }
        }
        
        mockito:
        
        @ExtenDWith(mockitoExtension.class)
        public class ConfigDatasourceTest {
            @mock
           private PropertIEs propertIEs;
        
            @Injectmocks
            private ConfigDatasource configDatasource;
        
            @Test
            public voID configDatasourcetest() {
                String jdbcUrl = "jdbc:Oracle:thin:teste:swd001";
                String username = "teste";
                String password = "teste";
                String divreClassname = "Oracle.jdbc.driver.OracleDriver";
                Integer connectionTimeout = 20000;
                Integer minimumIDle = 100;
                Integer maximumPoolSize = 10;
                Integer IDleTimeout = 10000;
                Integer maxlifetime = 1000;
        
                when(propertIEs.getDriveClassname()).thenReturn(divreClassName);
                when(propertIEs.getConnectionTimeout()).thenReturn(connectionTimeout);
                when(propertIEs.getMinimumIDle()).thenReturn(minimumIDlE);
                when(propertIEs.getMaximumPoolSize()).thenReturn(maximumPoolSizE);
                when(propertIEs.getIDleTimeout()).thenReturn(IDleTimeout);
                when(propertIEs.getMaxlifetime()).thenReturn(maxlifetimE);
                
                
                Datasource result = configDatasource.getDatasource(jdbcUrl,username,password);
        
                assertNotNull(result);
            }
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的HikariPool-1 - 无法从 mockito 中的数据源获取连接全部内容,希望文章能够帮你解决HikariPool-1 - 无法从 mockito 中的数据源获取连接所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。