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

fix transaction isolation level check bug #15

Open
wants to merge 3 commits into
base: 3.4
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ jdk:

script:
- mvn clean test
dist: trusty
#- mvn clean test -Pperformance-test
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ protected Neo4jConnectionImpl(Properties properties, String url, int defaultHold
this.holdability = defaultHoldability;
}

Neo4jConnectionImpl() {}

public static boolean hasDebug(Properties properties) {
return "true".equalsIgnoreCase(properties.getProperty("debug", "false"));
}
Expand Down Expand Up @@ -229,7 +231,7 @@ protected void checkTypeParams(int resultSetType) throws SQLException {
*/
protected void checkTransactionIsolation(int level) throws SQLException {
// @formatter:off
int[] invalid = {
Integer[] invalid = {
TRANSACTION_NONE,
TRANSACTION_READ_COMMITTED,
TRANSACTION_READ_UNCOMMITTED,
Expand All @@ -238,7 +240,7 @@ protected void checkTransactionIsolation(int level) throws SQLException {
};

if(!Arrays.asList(invalid).contains(level)){
throw new SQLException();
throw new SQLException("Unsupported isolation level");
}
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.neo4j.jdbc.impl;

import org.junit.Test;

import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import static org.junit.Assert.fail;

/**
* @description
* @time 创建时间:2019/9/3 0:44
* @param
* @author xin.gong
*/
public class Neo4jConnectionImplTest {

Neo4jConnectionImpl neo4jConnection = new Neo4jConnectionImpl(){
@Override public Statement createStatement() throws SQLException {
return null;
}

@Override public PreparedStatement prepareStatement(String sql) throws SQLException {
return null;
}

@Override public void setAutoCommit(boolean autoCommit) throws SQLException {

}

@Override public boolean getAutoCommit() throws SQLException {
return false;
}

@Override public void commit() throws SQLException {

}

@Override public void rollback() throws SQLException {

}

@Override public void close() throws SQLException {

}

@Override public boolean isClosed() throws SQLException {
return false;
}

@Override public DatabaseMetaData getMetaData() throws SQLException {
return null;
}

@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
return null;
}

@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
return null;
}

@Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
return null;
}

@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
return null;
}

@Override public boolean isValid(int timeout) throws SQLException {
return false;
}
};
@Test public void checkTransactionIsolationShouldReturnNothing() {
Integer[] levels = {0, 1, 2, 4, 8};
for (int level : levels) {
try {
neo4jConnection.checkTransactionIsolation(level);
} catch (SQLException e) {
fail();
}
}
}

@Test public void checkTransactionIsolationShouldThrowExceptionWhenInputErrorLevel() {
Integer[] levels = {3, 5, 7, 9};
for (int level : levels) {
try {
neo4jConnection.checkTransactionIsolation(level);
fail();
} catch (SQLException e) {
// OK
}
}
}
}