terrymanu commented on a change in pull request #14561: URL: https://github.com/apache/shardingsphere/pull/14561#discussion_r790147176
########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactoryTest.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.Test; + +public final class DataSourcePoolDestroyerFactoryTest { + + @Test(timeout = 60000) + public void assertDestroyForHikari() throws InterruptedException { + try { + HikariDataSource dataSource = new HikariDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. + Thread.sleep(10L); + } + } catch (SQLException ex) { + fail(); Review comment: Is it necessary to catch exception and assert fail here, how about throw SQLException in method signature? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactoryTest.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.Test; + +public final class DataSourcePoolDestroyerFactoryTest { + + @Test(timeout = 60000) Review comment: Please add `L` as suffix for long value ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; + +public final class HikariDataSourcePoolDestroyerTest { + + @Test(timeout = 60000) + public void assertDestroy() throws InterruptedException { + HikariDataSource dataSource = new HikariDataSource(); + new HikariDataSourcePoolDestroyer().destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. + Thread.sleep(10L); + } + } + + @Test + public void assertGetType() { + assertThat(new HikariDataSourcePoolDestroyer().getType(), is(HikariDataSource.class.getCanonicalName())); + } Review comment: There is unnecessary to assert static get method, could you remove this test case? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; + +public final class HikariDataSourcePoolDestroyerTest { + + @Test(timeout = 60000) + public void assertDestroy() throws InterruptedException { + HikariDataSource dataSource = new HikariDataSource(); + new HikariDataSourcePoolDestroyer().destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. Review comment: Could you remove the comment? I think the code has already explain all things. ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactoryTest.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.Test; + +public final class DataSourcePoolDestroyerFactoryTest { + + @Test(timeout = 60000) + public void assertDestroyForHikari() throws InterruptedException { + try { + HikariDataSource dataSource = new HikariDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. + Thread.sleep(10L); + } + } catch (SQLException ex) { + fail(); + } + } + + @Test + public void assertDestroyForDefault() throws InterruptedException { + try { + BasicDataSource dataSource = new BasicDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + assertThat(dataSource.isClosed(), is(true)); + } catch (SQLException ex) { + fail(); + } Review comment: Is it necessary to catch exception and assert fail here, how about throw SQLException in method signature? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactoryTest.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.Test; + +public final class DataSourcePoolDestroyerFactoryTest { + + @Test(timeout = 60000) + public void assertDestroyForHikari() throws InterruptedException { + try { + HikariDataSource dataSource = new HikariDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. + Thread.sleep(10L); + } + } catch (SQLException ex) { + fail(); + } + } + + @Test + public void assertDestroyForDefault() throws InterruptedException { + try { + BasicDataSource dataSource = new BasicDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + assertThat(dataSource.isClosed(), is(true)); Review comment: Please use assertTrue for unary assertion ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; + +public final class HikariDataSourcePoolDestroyerTest { + + @Test(timeout = 60000) + public void assertDestroy() throws InterruptedException { + HikariDataSource dataSource = new HikariDataSource(); + new HikariDataSourcePoolDestroyer().destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. + Thread.sleep(10L); + } + } + + @Test + public void assertGetType() { + assertThat(new HikariDataSourcePoolDestroyer().getType(), is(HikariDataSource.class.getCanonicalName())); + } + + @Test + public void assertIsDefault() { + assertFalse(new HikariDataSourcePoolDestroyer().isDefault()); + } Review comment: There is unnecessary to assert static get method, could you remove this test case? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/DefaultDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public final class DefaultDataSourcePoolDestroyerTest { + + @Test + public void assertDestroy() { + try { + HikariDataSource dataSource = new HikariDataSource(); + new DefaultDataSourcePoolDestroyer().destroy(dataSource); + assertThat(dataSource.isClosed(), is(true)); + } catch (SQLException ex) { + fail(); + } + } + + @Test(expected = SQLException.class) + public void assertDestroyWithException() throws SQLException { + HikariDataSource dataSource = mock(HikariDataSource.class); + doThrow(new RuntimeException()).when(dataSource).close(); + new DefaultDataSourcePoolDestroyer().destroy(dataSource); + } + + @Test + public void assertGetType() { + assertThat(new DefaultDataSourcePoolDestroyer().getType(), is("Default")); + } Review comment: There is unnecessary to assert static get method, could you remove this test case? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/DefaultDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public final class DefaultDataSourcePoolDestroyerTest { + + @Test + public void assertDestroy() { + try { + HikariDataSource dataSource = new HikariDataSource(); + new DefaultDataSourcePoolDestroyer().destroy(dataSource); + assertThat(dataSource.isClosed(), is(true)); + } catch (SQLException ex) { + fail(); + } + } + + @Test(expected = SQLException.class) + public void assertDestroyWithException() throws SQLException { + HikariDataSource dataSource = mock(HikariDataSource.class); + doThrow(new RuntimeException()).when(dataSource).close(); + new DefaultDataSourcePoolDestroyer().destroy(dataSource); + } + + @Test + public void assertGetType() { + assertThat(new DefaultDataSourcePoolDestroyer().getType(), is("Default")); + } + + @Test + public void assertIsDefault() { + assertTrue(new DefaultDataSourcePoolDestroyer().isDefault()); + } Review comment: There is unnecessary to assert static get method, could you remove this test case? ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/DefaultDataSourcePoolDestroyerTest.java ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public final class DefaultDataSourcePoolDestroyerTest { + + @Test + public void assertDestroy() { + try { + HikariDataSource dataSource = new HikariDataSource(); + new DefaultDataSourcePoolDestroyer().destroy(dataSource); + assertThat(dataSource.isClosed(), is(true)); Review comment: Please use assertTrue for unary assertion ########## File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactoryTest.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.config.datasource.pool.destroyer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.sql.SQLException; + +import com.zaxxer.hikari.HikariDataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.Test; + +public final class DataSourcePoolDestroyerFactoryTest { + + @Test(timeout = 60000) + public void assertDestroyForHikari() throws InterruptedException { + try { + HikariDataSource dataSource = new HikariDataSource(); + DataSourcePoolDestroyerFactory.destroy(dataSource); + while (!dataSource.isClosed()) { + // Test will fail by timeout if dataSource is not closed. Review comment: Could you remove the comment? I think the code has already explain all things. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
