From a3b70e92e162f1832f2776bfc1e457ab81af4f79 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sat, 15 Jun 2013 11:55:34 +0800 Subject: [PATCH] remove unused code & add testcase --- .../druid/sql/visitor/SQLShardingContext.java | 21 ----- .../bvt/pool/xa/JtdsXAConnectionTest.java | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/com/alibaba/druid/sql/visitor/SQLShardingContext.java create mode 100644 src/test/java/com/alibaba/druid/bvt/pool/xa/JtdsXAConnectionTest.java diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLShardingContext.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLShardingContext.java deleted file mode 100644 index ecae764c5f..0000000000 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLShardingContext.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.sql.visitor; - - -public class SQLShardingContext { - -} diff --git a/src/test/java/com/alibaba/druid/bvt/pool/xa/JtdsXAConnectionTest.java b/src/test/java/com/alibaba/druid/bvt/pool/xa/JtdsXAConnectionTest.java new file mode 100644 index 0000000000..491ea58334 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/pool/xa/JtdsXAConnectionTest.java @@ -0,0 +1,83 @@ +package com.alibaba.druid.bvt.pool.xa; + +import java.lang.reflect.Constructor; + +import junit.framework.TestCase; +import net.sourceforge.jtds.jdbc.JtdsConnection; + +import org.junit.Assert; + +import com.alibaba.druid.pool.xa.JtdsXAConnection; +import com.alibaba.druid.pool.xa.JtdsXAResource; + +public class JtdsXAConnectionTest extends TestCase { + + public void test_jtds() throws Exception { + Constructor constrcutor = JtdsConnection.class.getDeclaredConstructor(); + constrcutor.setAccessible(true); + JtdsConnection jtdsConn = constrcutor.newInstance(); + JtdsXAConnection xaConn = new JtdsXAConnection(jtdsConn); + Assert.assertSame(jtdsConn, xaConn.getConnection()); + + JtdsXAResource xaResource = (JtdsXAResource) xaConn.getXAResource(); + Assert.assertTrue(xaResource.isSameRM(xaResource)); + Assert.assertFalse(xaResource.isSameRM(null)); + + { + Exception error = null; + try { + xaResource.commit(null, true); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + { + Exception error = null; + try { + xaResource.start(null, 0); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + { + Exception error = null; + try { + xaResource.end(null, 0); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + { + Exception error = null; + try { + xaResource.forget(null); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + { + Exception error = null; + try { + xaResource.rollback(null); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + xaResource.recover(0); + { + Exception error = null; + try { + xaResource.prepare(null); + } catch (Exception ex) { + error = ex; + } + Assert.assertNotNull(error); + } + xaConn.close(); + } +}