Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-05-19 14:46:25 +0000
committerEike Stepper2013-05-19 14:46:25 +0000
commit24770a2a8333d5e18df024f1bbc851430b0e9734 (patch)
tree463f2a706e9804aafeef6ce8bd8d6435eae92be6 /plugins/org.eclipse.emf.cdo.tests.db
parent3d9da56810c62e5fe04dd7d9ee6f00cce68065fe (diff)
downloadcdo-24770a2a8333d5e18df024f1bbc851430b0e9734.tar.gz
cdo-24770a2a8333d5e18df024f1bbc851430b0e9734.tar.xz
cdo-24770a2a8333d5e18df024f1bbc851430b0e9734.zip
[323006] [DB] Various PostgreSQL test failures
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323006
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests.db')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL ALL).launch (renamed from plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL non-audit).launch)0
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/build.properties2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBPsql.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java158
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java43
5 files changed, 86 insertions, 119 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL non-audit).launch b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL ALL).launch
index d624f94450..d624f94450 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL non-audit).launch
+++ b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (PostgreSQL ALL).launch
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/build.properties b/plugins/org.eclipse.emf.cdo.tests.db/build.properties
index d017d59937..41e5bee44e 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/build.properties
+++ b/plugins/org.eclipse.emf.cdo.tests.db/build.properties
@@ -27,7 +27,7 @@ src.includes = about.html,\
CDO AllTests (Hsqldb audit).launch,\
CDO AllTests (Hsqldb non-audit).launch,\
CDO AllTests (Mysql).launch,\
- CDO AllTests (PostgreSQL non-audit).launch,\
+ CDO AllTests (PostgreSQL ALL).launch,\
CDO AllTests (DBStore).launch,\
CDO AllTests (H2 ALL).launch,\
CDO AllTests (H2 UUIDs).launch,\
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBPsql.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBPsql.java
index 0caf84da70..00abaf36b5 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBPsql.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBPsql.java
@@ -38,5 +38,7 @@ public class AllTestsDBPsql extends DBConfigs
protected void initConfigSuites(TestSuite parent)
{
addScenario(parent, COMBINED, new PostgresqlConfig(false, false, IDGenerationLocation.STORE), JVM, NATIVE);
+ addScenario(parent, COMBINED, new PostgresqlConfig(true, false, IDGenerationLocation.STORE), JVM, NATIVE);
+ addScenario(parent, COMBINED, new PostgresqlConfig(true, true, IDGenerationLocation.STORE), JVM, NATIVE);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
index 1fa09f86ef..cdc06bbc14 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
@@ -21,6 +21,7 @@ import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.io.ExtendedIOUtil;
import org.eclipse.net4j.util.io.IOUtil;
import java.io.ByteArrayInputStream;
@@ -46,19 +47,12 @@ public class Net4jDBTest extends AbstractCDOTest
{
private static final String FIELD_NAME = "testField";
- private ArrayList<Pair<DBType, Object>> columns = new ArrayList<Pair<DBType, Object>>();
-
- private DBStore store;
-
- private Connection connection;
+ private transient ArrayList<Pair<DBType, Object>> columns = new ArrayList<Pair<DBType, Object>>();
@Override
protected void doTearDown() throws Exception
{
columns.clear();
- columns = null;
- store = null;
- connection = null;
super.doTearDown();
}
@@ -158,7 +152,7 @@ public class Net4jDBTest extends AbstractCDOTest
{
registerColumn(DBType.CLOB, "Test");
- StringBuffer b = new StringBuffer();
+ StringBuilder b = new StringBuilder();
for (int i = 0; i < 1000000; i++)
{
b.append("x");
@@ -336,13 +330,31 @@ public class Net4jDBTest extends AbstractCDOTest
doTest(getName());
}
- private void registerColumn(DBType type, Object value)
+ private void registerColumn(DBType type, Object value) throws IOException
{
+ testIOSymmetry(type, value);
+
Pair<DBType, Object> column = Pair.create(type, value);
columns.add(column);
}
- private void prepareTable(final String tableName)
+ private void testIOSymmetry(DBType type, Object value) throws IOException
+ {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ExtendedDataOutputStream outs = new ExtendedDataOutputStream(output);
+ writeTypeValue(outs, type, value);
+ outs.close();
+ output.flush();
+ byte[] buffer = output.toByteArray();
+ output.close();
+
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+ ExtendedDataInputStream ins = new ExtendedDataInputStream(input);
+ Object actualValue = readTypeValue(ins, type);
+ assertEquals(value, actualValue, type, -1);
+ }
+
+ private void prepareTable(DBStore store, final String tableName)
{
IDBDatabase database = store.getDatabase();
database.updateSchema(new IDBDatabase.RunnableWithSchema()
@@ -371,7 +383,7 @@ public class Net4jDBTest extends AbstractCDOTest
});
}
- private void writeValues(String tableName) throws Exception
+ private void writeValues(Connection connection, String tableName) throws Exception
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExtendedDataOutputStream outs = new ExtendedDataOutputStream(output);
@@ -418,7 +430,7 @@ public class Net4jDBTest extends AbstractCDOTest
input.close();
}
- private void checkValues(String tableName) throws Exception
+ private void checkValues(Connection connection, String tableName) throws Exception
{
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM " + tableName);
@@ -430,7 +442,8 @@ public class Net4jDBTest extends AbstractCDOTest
int c = 1;
for (Pair<DBType, Object> column : columns)
{
- column.getElement1().writeValue(outs, resultSet, c++, false);
+ DBType dbType = column.getElement1();
+ dbType.writeValue(outs, resultSet, c++, false);
}
resultSet.close();
@@ -451,50 +464,53 @@ public class Net4jDBTest extends AbstractCDOTest
Object expected = column.getElement2();
Object actual = readTypeValue(ins, dbType);
- Class<? extends Object> type = expected.getClass();
- if (type.isArray())
+ assertEquals(expected, actual, dbType, c++);
+ }
+ }
+
+ private void assertEquals(Object expected, Object actual, DBType dbType, int c)
+ {
+ Class<? extends Object> type = expected.getClass();
+ if (type.isArray())
+ {
+ Class<?> componentType = type.getComponentType();
+ if (componentType == byte.class)
{
- Class<?> componentType = type.getComponentType();
- if (componentType == byte.class)
- {
- assertEquals("Error in column " + c + " of type " + dbType, true,
- Arrays.equals((byte[])expected, (byte[])actual));
- }
- else if (componentType == char.class)
- {
- assertEquals("Error in column " + c + " with type " + dbType, true,
- Arrays.equals((char[])expected, (char[])actual));
- }
- else
- {
- throw new IllegalStateException("Unexpected component type: " + componentType);
- }
+ assertEquals("Error in column " + c + " of type " + dbType, true,
+ Arrays.equals((byte[])expected, (byte[])actual));
+ }
+ else if (componentType == char.class)
+ {
+ assertEquals("Error in column " + c + " with type " + dbType, true,
+ Arrays.equals((char[])expected, (char[])actual));
}
else
{
- if (dbType == DBType.TIME)
- {
- actual = (Long)actual % 86400000L;
- expected = (Long)expected % 86400000L;
- }
-
- assertEquals("Error in column " + c + " with type " + dbType, expected, actual);
+ throw new IllegalStateException("Unexpected component type: " + componentType);
+ }
+ }
+ else
+ {
+ if (dbType == DBType.TIME)
+ {
+ actual = (Long)actual % 86400000L;
+ expected = (Long)expected % 86400000L;
}
- ++c;
+ assertEquals("Error in column " + c + " with type " + dbType, expected, actual);
}
}
private void doTest(String tableName) throws Exception
{
- store = (DBStore)getRepository().getStore();
- connection = store.getConnection();
+ DBStore store = (DBStore)getRepository().getStore();
+ Connection connection = store.getConnection();
try
{
- prepareTable(tableName);
- writeValues(tableName);
- checkValues(tableName);
+ prepareTable(store, tableName);
+ writeValues(connection, tableName);
+ checkValues(connection, tableName);
}
finally
{
@@ -563,25 +579,8 @@ public class Net4jDBTest extends AbstractCDOTest
return;
case CLOB:
- {
- long length = ((String)value).length();
- StringReader source = new StringReader((String)value);
- try
- {
- outs.writeLong(length);
- while (length-- > 0)
- {
- int c = source.read();
- outs.writeChar(c);
- }
- }
- finally
- {
- IOUtil.close(source);
- }
-
+ ExtendedIOUtil.writeCharacterStream(outs, new StringReader((String)value));
return;
- }
case BIGINT:
case DATE:
@@ -597,25 +596,8 @@ public class Net4jDBTest extends AbstractCDOTest
return;
case BLOB:
- {
- long length = ((byte[])value).length;
- ByteArrayInputStream source = new ByteArrayInputStream((byte[])value);
- try
- {
- outs.writeLong(length);
- while (length-- > 0)
- {
- int b = source.read();
- outs.writeByte(b + Byte.MIN_VALUE);
- }
- }
- finally
- {
- IOUtil.close(source);
- }
-
+ ExtendedIOUtil.writeBinaryStream(outs, new ByteArrayInputStream((byte[])value));
return;
- }
default:
throw new UnsupportedOperationException("not implemented");
@@ -670,19 +652,16 @@ public class Net4jDBTest extends AbstractCDOTest
case CLOB:
{
StringWriter result = new StringWriter();
+
try
{
- long length = ins.readLong();
- while (length-- > 0)
- {
- char c = ins.readChar();
- result.append(c);
- }
+ ExtendedIOUtil.readCharacterStream(ins, result);
}
finally
{
IOUtil.close(result);
}
+
return result.toString();
}
@@ -703,12 +682,7 @@ public class Net4jDBTest extends AbstractCDOTest
try
{
- long length = ins.readLong();
- while (length-- > 0)
- {
- int b = ins.readByte();
- result.write(b - Byte.MIN_VALUE);
- }
+ ExtendedIOUtil.readBinaryStream(ins, result);
}
finally
{
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java
index 21fcffd167..c35c708403 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/PostgresqlConfig.java
@@ -37,9 +37,9 @@ public class PostgresqlConfig extends DBConfig
private transient PGSimpleDataSource dataSource;
- private transient PGSimpleDataSource setupDataSource;
+ // private transient PGSimpleDataSource setupDataSource;
- private String currentRepositoryName = "cdodb1";
+ // private transient String currentRepositoryName;
public PostgresqlConfig(boolean supportingAudits, boolean supportingBranches,
IDGenerationLocation idGenerationLocation)
@@ -62,13 +62,7 @@ public class PostgresqlConfig extends DBConfig
@Override
protected DataSource createDataSource(String repoName)
{
- currentRepositoryName = repoName;
-
- dataSource = new PGSimpleDataSource();
- dataSource.setServerName("localhost");
- dataSource.setDatabaseName(currentRepositoryName);
- dataSource.setUser("sa");
- dataSource.setPassword("sa");
+ dataSource = internalCreateDataSource(repoName);
try
{
@@ -88,9 +82,8 @@ public class PostgresqlConfig extends DBConfig
protected void deactivateRepositories()
{
super.deactivateRepositories();
- dataSource = null;
- setupDataSource = null;
dropDatabase();
+ dataSource = null;
}
private void dropDatabase()
@@ -99,12 +92,14 @@ public class PostgresqlConfig extends DBConfig
try
{
- connection = getSetupDataSource().getConnection();
- DBUtil.dropAllTables(connection, currentRepositoryName);
+ connection = dataSource.getConnection();
+ String databaseName = dataSource.getDatabaseName();
+
+ DBUtil.dropAllTables(connection, databaseName);
}
- catch (SQLException ignore)
+ catch (SQLException ex)
{
- IOUtil.ERR().println(ignore);
+ IOUtil.ERR().println(ex);
}
finally
{
@@ -112,17 +107,13 @@ public class PostgresqlConfig extends DBConfig
}
}
- private DataSource getSetupDataSource()
+ private PGSimpleDataSource internalCreateDataSource(String databaseName)
{
- if (setupDataSource == null)
- {
- setupDataSource = new PGSimpleDataSource();
- setupDataSource.setServerName("localhost");
- setupDataSource.setDatabaseName(currentRepositoryName);
- setupDataSource.setUser("sa");
- setupDataSource.setPassword("sa");
- }
-
- return setupDataSource;
+ PGSimpleDataSource dataSource = new PGSimpleDataSource();
+ dataSource.setServerName("localhost");
+ dataSource.setDatabaseName(databaseName);
+ dataSource.setUser("postgres");
+ dataSource.setPassword("postgres");
+ return dataSource;
}
}

Back to the top