Skip to content
Snippets Groups Projects
Commit 5ff4608f authored by kruthar's avatar kruthar
Browse files

[jdbc] testing code cleanup

reverted a few things that were not necessary
* semicolon change - coming in another PR
* .gitignore change - no longer using derby

Code cleanup
* test scoped hsqldb
* removed derby artifacts and references
* setting driver class is not necessary
* cleaned up unused objects in delete
* now running cleanup on client
* removed old assert(true) stub
parent 22085f62
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ target
# ignore output files from testing
output*
derby.log
# ignore standard eclipse
.project
......
......@@ -51,6 +51,7 @@ LICENSE file.
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -245,7 +245,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
for (int i = 0; i < insertType.numFields; i++) {
insert.append(",?");
}
insert.append(")");
insert.append(");");
PreparedStatement insertStatement = getShardConnectionByKey(key).prepareStatement(insert.toString());
PreparedStatement stmt = cachedStatements.putIfAbsent(insertType, insertStatement);
if (stmt == null) return insertStatement;
......@@ -259,7 +259,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
read.append(" WHERE ");
read.append(PRIMARY_KEY);
read.append(" = ");
read.append("?");
read.append("?;");
PreparedStatement readStatement = getShardConnectionByKey(key).prepareStatement(read.toString());
PreparedStatement stmt = cachedStatements.putIfAbsent(readType, readStatement);
if (stmt == null) return readStatement;
......@@ -272,7 +272,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
delete.append(deleteType.tableName);
delete.append(" WHERE ");
delete.append(PRIMARY_KEY);
delete.append(" = ?");
delete.append(" = ?;");
PreparedStatement deleteStatement = getShardConnectionByKey(key).prepareStatement(delete.toString());
PreparedStatement stmt = cachedStatements.putIfAbsent(deleteType, deleteStatement);
if (stmt == null) return deleteStatement;
......@@ -292,7 +292,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants {
}
update.append(" WHERE ");
update.append(PRIMARY_KEY);
update.append(" = ?");
update.append(" = ?;");
PreparedStatement insertStatement = getShardConnectionByKey(key).prepareStatement(update.toString());
PreparedStatement stmt = cachedStatements.putIfAbsent(updateType, insertStatement);
if (stmt == null) return insertStatement;
......
/**
* Copyright (c) 2015 Yahoo! Inc. All rights reserved.
*
* 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. See accompanying
* LICENSE file.
*/
package com.yahoo.ycsb.db;
import static org.junit.Assert.*;
......@@ -33,9 +50,7 @@ public class JdbcDBClientTest {
@BeforeClass
public static void setup() {
try {
Class driverClass = Class.forName(TEST_DB_DRIVER);
jdbcConnection = DriverManager.getConnection(TEST_DB_URL);
jdbcDBClient = new JdbcDBClient();
Properties p = new Properties();
......@@ -45,10 +60,6 @@ public class JdbcDBClientTest {
jdbcDBClient.setProperties(p);
jdbcDBClient.init();
} catch (ClassNotFoundException e) {
e.printStackTrace();
fail("Could not find Driver Class: " + TEST_DB_DRIVER);
} catch (SQLException e) {
e.printStackTrace();
fail("Could not create local Database");
......@@ -61,13 +72,19 @@ public class JdbcDBClientTest {
@AfterClass
public static void teardown() {
try {
jdbcConnection.close();
jdbcConnection = DriverManager.getConnection(TEST_DB_URL + ";shutdown=true");
} catch (SQLNonTransientConnectionException e) {
// Expected exception when database is destroyed
if (jdbcConnection != null) {
jdbcConnection.close();
}
} catch (SQLException e) {
e.printStackTrace();
fail("Could not drop local Database");
}
try {
if (jdbcDBClient != null) {
jdbcDBClient.cleanup();
}
} catch (DBException e) {
e.printStackTrace();
}
}
......@@ -98,7 +115,6 @@ public class JdbcDBClientTest {
e.printStackTrace();
fail("Failed to prepare test");
}
}
/*
......@@ -224,9 +240,6 @@ public class JdbcDBClientTest {
e.printStackTrace();
fail("Failed updateTest");
}
assertTrue(true);
}
@Test
......@@ -263,12 +276,10 @@ public class JdbcDBClientTest {
@Test
public void deleteTest() {
try {
String insertBeforeKey = "user0";
HashMap<String, ByteIterator> insertBeforeMap = insertRow(insertBeforeKey);
insertRow("user0");
String deleteKey = "user1";
insertRow(deleteKey);
String insertAfterKey = "user2";
HashMap<String, ByteIterator> insertAfterMap = insertRow(insertAfterKey);
insertRow("user2");
jdbcDBClient.delete(TABLE_NAME, deleteKey);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment