Commit 3bbf1fab authored by terrymanu's avatar terrymanu
Browse files

for #1699, throw SQLException instead of ShardingException

parent 5c4b64b3
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
import io.shardingsphere.shardingjdbc.jdbc.adapter.executor.ForceExecuteCallback;
@@ -160,7 +159,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
                for (Connection each : result) {
                    each.close();
                }
                throw new ShardingException(String.format("Could't get %d connections one time, partition succeed connection(%d) have released!", connectionSize, result.size()));
                throw new SQLException(String.format("Could't get %d connections one time, partition succeed connection(%d) have released!", connectionSize, result.size()), ex);
            }
        }
        return result;
+2 −2
Original line number Diff line number Diff line
@@ -130,11 +130,11 @@ public final class JDBCBackendDataSource implements BackendDataSource, AutoClose
        for (int i = 0; i < connectionSize; i++) {
            try {
                result.add(dataSource.getConnection());
            } catch (final SQLException ignored) {
            } catch (final SQLException ex) {
                for (Connection each : result) {
                    each.close();
                }
                throw new ShardingException(String.format("Could't get %d connections one time, partition succeed connection(%d) have released!", connectionSize, result.size()));
                throw new SQLException(String.format("Could't get %d connections one time, partition succeed connection(%d) have released!", connectionSize, result.size()), ex);
            }
        }
        return result;
+2 −8
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
package io.shardingsphere.shardingproxy.backend.jdbc.datasource;

import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.exception.ShardingException;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.junit.Before;
@@ -39,7 +38,6 @@ import java.util.concurrent.Future;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -80,13 +78,9 @@ public class JDBCBackendDataSourceTest {
        assertEquals(5, actual.size());
    }
    
    @Test
    @Test(expected = SQLException.class)
    public void assertGetConnectionsFailed() throws SQLException {
        try {
        jdbcBackendDataSource.getConnections(ConnectionMode.MEMORY_STRICTLY, "ds_1", 6);
        } catch (final ShardingException ex) {
            assertThat(ex.getMessage(), is("Could't get 6 connections one time, partition succeed connection(5) have released!"));
        }
    }
    
    @Test