Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add KeyspaceNotExistTest #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/jd/jdbc/vitess/VitessDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public Connection initConnect(String url, Properties info, boolean initOnly) thr
}
}
return new VitessConnection(url, prop, topoServer, resolver, vSchemaManager, defaultKeyspace);
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/com/jd/jdbc/vitess/KeyspaceNotExistTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2021 JD Project Authors.

Licensed 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 com.jd.jdbc.vitess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.sql.Statement;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import testsuite.TestSuite;
import testsuite.internal.TestSuiteShardSpec;

public class KeyspaceNotExistTest extends TestSuite {
@Rule
public final ExpectedException thrown = ExpectedException.none();

@Test
public void case05() throws SQLException {
String keyspace = getKeyspace(Driver.of(TestSuiteShardSpec.TWO_SHARDS));
String connectionUrl = getConnectionUrl(Driver.of(TestSuiteShardSpec.TWO_SHARDS));
String keyspaceNotExist = keyspace + "not_exist";
connectionUrl = connectionUrl.replaceAll(keyspace, keyspaceNotExist);
thrown.expect(SQLSyntaxErrorException.class);
thrown.expectMessage("Unknown database '" + keyspaceNotExist + "'");
try (Connection connection = DriverManager.getConnection(connectionUrl);
Statement stmt = connection.createStatement();) {
stmt.executeQuery("select 1");
}
}
}
Loading