Skip to content

Commit

Permalink
IGNITE-4192: JDBC support for transactions. This closes apache#3169.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpaschenko authored and devozerov committed Dec 21, 2017
1 parent 2d80df3 commit 090eb92
Show file tree
Hide file tree
Showing 38 changed files with 1,748 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.ignite.jdbc.thin.JdbcThinAutoCloseServerCursorTest;
import org.apache.ignite.jdbc.thin.JdbcThinBatchSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinComplexDmlDdlSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinComplexDmlDdlSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinComplexQuerySelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinConnectionSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinDeleteStatementSelfTest;
Expand All @@ -48,7 +49,9 @@
import org.apache.ignite.jdbc.thin.JdbcThinEmptyCacheSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinErrorsSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinInsertStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinInsertStatementSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinMergeStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinMergeStatementSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinMetadataSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinMissingLongArrayResultsTest;
import org.apache.ignite.jdbc.thin.JdbcThinNoDefaultSchemaTest;
Expand All @@ -57,10 +60,8 @@
import org.apache.ignite.jdbc.thin.JdbcThinSchemaCaseTest;
import org.apache.ignite.jdbc.thin.JdbcThinSelectAfterAlterTable;
import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinTransactionsSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinUpdateStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinComplexDmlDdlSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinInsertStatementSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinMergeStatementSkipReducerOnUpdateSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinUpdateStatementSkipReducerOnUpdateSelfTest;

/**
Expand Down Expand Up @@ -162,6 +163,9 @@ public static TestSuite suite() throws Exception {
suite.addTest(new TestSuite(JdbcThinMergeStatementSkipReducerOnUpdateSelfTest.class));
suite.addTest(new TestSuite(JdbcThinComplexDmlDdlSkipReducerOnUpdateSelfTest.class));

// Transactions
suite.addTest(new TestSuite(JdbcThinTransactionsSelfTest.class));


return suite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.ignite.jdbc.thin;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
Expand All @@ -33,15 +36,19 @@
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.jdbc.thin.ConnectionProperties;
import org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl;
import org.apache.ignite.internal.jdbc.thin.JdbcThinConnection;
import org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo;
import org.apache.ignite.internal.jdbc.thin.JdbcThinUtils;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
import org.apache.ignite.testframework.GridStringLogger;
import org.apache.ignite.testframework.GridTestUtils;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -83,6 +90,8 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest {

cfg.setMarshaller(new BinaryMarshaller());

cfg.setGridLogger(new GridStringLogger());

return cfg;
}

Expand Down Expand Up @@ -900,7 +909,7 @@ public void testRollback() throws Exception {
}
},
SQLException.class,
"Transaction cannot rollback in auto-commit mode"
"Transaction cannot be rolled back explicitly in auto-commit mode."
);

conn.setAutoCommit(false);
Expand Down Expand Up @@ -1756,6 +1765,58 @@ public void testGetSetNetworkTimeout() throws Exception {
}
}

/**
* Test that attempting to supply invalid nested TX mode to driver fails on the client.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testInvalidNestedTxMode() {
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override public Object call() throws Exception {
DriverManager.getConnection(URL + "/?nestedTransactionsMode=invalid");

return null;
}
}, SQLException.class, "Invalid nested transactions handling mode");
}

/**
* Test that attempting to send unexpected name of nested TX mode to server on handshake yields an error.
* We have to do this without explicit {@link Connection} as long as there's no other way to bypass validation and
* supply a malformed {@link ConnectionProperties} to {@link JdbcThinTcpIo}.
*/
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ThrowFromFinallyBlock"})
public void testInvalidNestedTxModeOnServerSide() throws SQLException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException, InstantiationException, IOException {
ConnectionPropertiesImpl connProps = new ConnectionPropertiesImpl();

connProps.setHost("127.0.0.1");

connProps.nestedTxMode("invalid");

Constructor ctor = JdbcThinTcpIo.class.getDeclaredConstructor(ConnectionProperties.class);

boolean acc = ctor.isAccessible();

ctor.setAccessible(true);

final JdbcThinTcpIo io = (JdbcThinTcpIo)ctor.newInstance(connProps);

try {
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override public Object call() throws Exception {
io.start();

return null;
}
}, SQLException.class, "err=Invalid nested transactions handling mode: invalid");
}
finally {
io.close();

ctor.setAccessible(acc);
}
}

/**
* @return Savepoint.
*/
Expand Down

0 comments on commit 090eb92

Please sign in to comment.