diff options
13 files changed, 765 insertions, 150 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (Mysql offline).launch b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (Mysql offline).launch new file mode 100644 index 0000000000..8d2fac1cf4 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/CDO AllTests (Mysql offline).launch @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<listAttribute key="com.chronon.sb.browser.launcher.launchattrs.excludePatterns"/> +<listAttribute key="com.chronon.sb.browser.launcher.launchattrs.includePatterns"> +<listEntry value="org.eclipse.**"/> +</listAttribute> +<intAttribute key="com.chronon.sb.browser.launcher.launchattrs.jretype" value="64"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysqlOffline.java"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.db.AllTestsDBMysqlOffline"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests.db"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx1024m -Dorg.eclipse.net4j.util.om.trace.disable=true"/> +</launchConfiguration> diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java index f874645435..fc06affe14 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java @@ -47,9 +47,9 @@ public class AllTestsDBH2Offline extends DBConfigs @Override protected void initConfigSuites(TestSuite parent) { - addScenario(parent, COMBINED, new H2OfflineConfig(false, false, IDGenerationLocation.STORE), JVM, NATIVE); + // addScenario(parent, COMBINED, new H2OfflineConfig(false, false, IDGenerationLocation.STORE), JVM, NATIVE); addScenario(parent, COMBINED, new H2OfflineConfig(false, false, IDGenerationLocation.CLIENT), JVM, NATIVE); - addScenario(parent, COMBINED, new H2OfflineConfig(true, false, IDGenerationLocation.STORE), JVM, NATIVE); + // addScenario(parent, COMBINED, new H2OfflineConfig(true, false, IDGenerationLocation.STORE), JVM, NATIVE); } @Override @@ -63,7 +63,6 @@ public class AllTestsDBH2Offline extends DBConfigs testClasses.add(OfflineLockReplicationTest.class); testClasses.add(OfflineLockRawReplicationTest.class); - testClasses.add(Bugzilla_351078_DB_Test.class); testClasses.add(Bugzilla_329014_Test.class); testClasses.add(Bugzilla_328352_Test.class); testClasses.add(Bugzilla_326047_Test.class); @@ -72,5 +71,6 @@ public class AllTestsDBH2Offline extends DBConfigs testClasses.add(Bugzilla_376470_Test.class); testClasses.add(Bugzilla_376566_Test.class); testClasses.add(Bugzilla_376567_Test.class); + testClasses.add(Bugzilla_377727_Test.class); } } diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysqlOffline.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysqlOffline.java new file mode 100644 index 0000000000..117a24b28e --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBMysqlOffline.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.tests.db; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.tests.config.IScenario; +import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_319552_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_325097_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_326047_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_328352_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_329014_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_376470_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_376566_Test; +import org.eclipse.emf.cdo.tests.offline.Bugzilla_376567_Test; +import org.eclipse.emf.cdo.tests.offline.FailoverTest; +import org.eclipse.emf.cdo.tests.offline.OfflineDelayedTest; +import org.eclipse.emf.cdo.tests.offline.OfflineLockRawReplicationTest; +import org.eclipse.emf.cdo.tests.offline.OfflineLockReplicationTest; +import org.eclipse.emf.cdo.tests.offline.OfflineLockingTest; +import org.eclipse.emf.cdo.tests.offline.OfflineRawTest; +import org.eclipse.emf.cdo.tests.offline.OfflineTest; + +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author Eike Stepper + */ +public class AllTestsDBMysqlOffline extends DBConfigs +{ + public static Test suite() + { + return new AllTestsDBMysqlOffline().getTestSuite("CDO Tests (DBStore Mysql Horizontal - offline mode)"); + } + + @Override + protected void initConfigSuites(TestSuite parent) + { + // addScenario(parent, COMBINED, new MysqlOfflineConfig(false, false, IDGenerationLocation.STORE), JVM, NATIVE); + addScenario(parent, COMBINED, new MysqlOfflineConfig(false, false, IDGenerationLocation.CLIENT), JVM, NATIVE); + // addScenario(parent, COMBINED, new MysqlOfflineConfig(true, false, IDGenerationLocation.STORE), JVM, NATIVE); + } + + @Override + protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario) + { + testClasses.add(FailoverTest.class); + testClasses.add(OfflineTest.class); + testClasses.add(OfflineRawTest.class); + testClasses.add(OfflineDelayedTest.class); + testClasses.add(OfflineLockingTest.class); + testClasses.add(OfflineLockReplicationTest.class); + testClasses.add(OfflineLockRawReplicationTest.class); + + testClasses.add(Bugzilla_329014_Test.class); + testClasses.add(Bugzilla_328352_Test.class); + testClasses.add(Bugzilla_326047_Test.class); + testClasses.add(Bugzilla_325097_Test.class); + testClasses.add(Bugzilla_319552_Test.class); + testClasses.add(Bugzilla_376470_Test.class); + testClasses.add(Bugzilla_376566_Test.class); + testClasses.add(Bugzilla_376567_Test.class); + testClasses.add(Bugzilla_377727_Test.class); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java index d8ed821cce..541d5a4b0f 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_351078_DB_Test.java @@ -36,7 +36,8 @@ public class Bugzilla_351078_DB_Test extends Bugzilla_351078_Test {
super.check(master, masterCompany, when);
- H2OfflineConfig config = (H2OfflineConfig)getRepositoryConfig();
+ // XXX use capabilities?!
+ DBOfflineConfig config = (DBOfflineConfig)getRepositoryConfig();
if (config.isWithRanges())
{
byte[] masterTable = readTable(master);
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_377727_Test.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_377727_Test.java new file mode 100644 index 0000000000..5a74d99886 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Bugzilla_377727_Test.java @@ -0,0 +1,104 @@ +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.db;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.OfflineConfig;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model3.Class1;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.util.Map;
+
+/**
+ * @author Stefan Winkler
+ */
+public class Bugzilla_377727_Test extends AbstractCDOTest
+{
+ @Override
+ public synchronized Map<String, Object> getTestProperties()
+ {
+ Map<String, Object> testProperties = super.getTestProperties();
+ testProperties.put(OfflineConfig.PROP_TEST_RAW_REPLICATION, Boolean.TRUE);
+ return testProperties;
+ }
+
+ @Requires(RepositoryConfig.CAPABILITY_OFFLINE)
+ @CleanRepositoriesBefore
+ public void testAsyncPackages() throws Exception
+ {
+ CDOID id1;
+ CDOID id2;
+
+ IOUtil.OUT().println("=== Disconnect clone ===");
+
+ // disconnect clone from master
+ ((OfflineConfig)getRepositoryConfig()).stopMasterTransport();
+ ConcurrencyUtil.sleep(1000L);
+ while (getRepository().getState() == CDOCommonRepository.State.ONLINE)
+ {
+ ConcurrencyUtil.sleep(250L);
+ }
+
+ IOUtil.OUT().println("=== Clone is disconnected ===");
+
+ {
+ // on disconnected master
+ CDOSession session = openSession("master");
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("test"));
+
+ Class1 c1 = getModel3Factory().createClass1();
+ resource.getContents().add(c1);
+ id1 = CDOUtil.getCDOObject(c1).cdoID();
+
+ Category cat1 = getModel1Factory().createCategory();
+ cat1.setName("Test");
+ resource.getContents().add(cat1);
+ id2 = CDOUtil.getCDOObject(cat1).cdoID();
+
+ transaction.commit();
+ transaction.close();
+ session.close();
+ }
+
+ // reconnect clone and let sync
+ IOUtil.OUT().println("=== reconnect clone ===");
+
+ ((OfflineConfig)getRepositoryConfig()).startMasterTransport();
+ while (getRepository().getState() != CDOCommonRepository.State.ONLINE)
+ {
+ ConcurrencyUtil.sleep(250L);
+ }
+
+ IOUtil.OUT().println("=== Clone is reconnected ===");
+
+ CDOSession session = openSession();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource(getResourcePath("test"));
+
+ Class1 c1 = (Class1)resource.getContents().get(0);
+ assertEquals(id1, CDOUtil.getCDOObject(c1).cdoID());
+
+ Category cat = (Category)resource.getContents().get(1);
+ assertEquals(id2, CDOUtil.getCDOObject(cat).cdoID());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBOfflineConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBOfflineConfig.java new file mode 100644 index 0000000000..12d547be59 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBOfflineConfig.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.tests.db; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.db.CDODBUtil; +import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy; +import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.OfflineConfig; + +import org.eclipse.net4j.db.DBUtil; +import org.eclipse.net4j.db.IDBAdapter; +import org.eclipse.net4j.db.IDBConnectionProvider; +import org.eclipse.net4j.util.container.IPluginContainer; + +import javax.sql.DataSource; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * @author Stefan Winkler + * @author Eike Stepper + */ +public abstract class DBOfflineConfig extends OfflineConfig +{ + private static final long serialVersionUID = 1L; + + private boolean withRanges; + + private boolean copyOnBranch; + + public DBOfflineConfig(String name, boolean withRanges, boolean copyOnBranch, + IDGenerationLocation idGenerationLocation) + { + super(name, idGenerationLocation); + this.withRanges = withRanges; + this.copyOnBranch = copyOnBranch; + } + + public boolean isWithRanges() + { + return withRanges; + } + + public boolean isCopyOnBranch() + { + return copyOnBranch; + } + + @Override + protected String getStoreName() + { + return MEMConfig.STORE_NAME; + } + + @Override + public void initCapabilities(Set<String> capabilities) + { + super.initCapabilities(capabilities); + + if (isWithRanges()) + { + capabilities.add(DBConfig.CAPABILITY_RANGES); + } + + if (isCopyOnBranch()) + { + capabilities.add(DBConfig.CAPABILITY_COPY_ON_BRANCH); + } + } + + public IStore createStore(String repoName) + { + IMappingStrategy mappingStrategy = createMappingStrategy(); + mappingStrategy.setProperties(createMappingStrategyProperties()); + + IDBAdapter dbAdapter = createDBAdapter(); + + DataSource dataSource = createDataSource(repoName); + IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource); + + return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider); + } + + @Override + public void setUp() throws Exception + { + CDODBUtil.prepareContainer(IPluginContainer.INSTANCE); + super.setUp(); + } + + protected Map<String, String> createMappingStrategyProperties() + { + Map<String, String> props = new HashMap<String, String>(); + props.put(IMappingStrategy.PROP_QUALIFIED_NAMES, "true"); + props.put(CDODBUtil.PROP_COPY_ON_BRANCH, Boolean.toString(copyOnBranch)); + return props; + } + + protected IMappingStrategy createMappingStrategy() + { + return CDODBUtil.createHorizontalMappingStrategy(isSupportingAudits(), isSupportingBranches(), withRanges); + } + + @Override + protected String getMappingStrategySpecialization() + { + return (withRanges ? "-ranges" : "") + (copyOnBranch ? "-copy" : ""); + } + + protected abstract DataSource createDataSource(String repoName); + + protected abstract IDBAdapter createDBAdapter(); +} diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java index 74b56ba6c5..3c2d918762 100644 --- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/H2OfflineConfig.java @@ -11,17 +11,11 @@ package org.eclipse.emf.cdo.tests.db;
import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.db.CDODBUtil;
-import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
-import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.OfflineConfig;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
-import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.h2.H2Adapter;
import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.io.TMPUtil;
@@ -32,14 +26,12 @@ import javax.sql.DataSource; import java.io.File;
import java.sql.Connection;
import java.sql.Statement;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Set;
/**
* @author Eike Stepper
*/
-public class H2OfflineConfig extends OfflineConfig
+public class H2OfflineConfig extends DBOfflineConfig
{
private static final long serialVersionUID = 1L;
@@ -47,31 +39,9 @@ public class H2OfflineConfig extends OfflineConfig private static JdbcDataSource defaultDataSource;
- private boolean withRanges;
-
- private boolean copyOnBranch;
-
public H2OfflineConfig(boolean withRanges, boolean copyOnBranch, IDGenerationLocation idGenerationLocation)
{
- super("H2Offline", idGenerationLocation);
- this.withRanges = withRanges;
- this.copyOnBranch = copyOnBranch;
- }
-
- @Override
- protected String getStoreName()
- {
- return MEMConfig.STORE_NAME;
- }
-
- public boolean isWithRanges()
- {
- return withRanges;
- }
-
- public boolean isCopyOnBranch()
- {
- return copyOnBranch;
+ super("H2Offline", withRanges, copyOnBranch, idGenerationLocation);
}
@Override
@@ -79,62 +49,15 @@ public class H2OfflineConfig extends OfflineConfig {
super.initCapabilities(capabilities);
capabilities.add(H2Config.DB_ADAPTER_NAME);
-
- if (isWithRanges())
- {
- capabilities.add(DBConfig.CAPABILITY_RANGES);
- }
-
- if (isCopyOnBranch())
- {
- capabilities.add(DBConfig.CAPABILITY_COPY_ON_BRANCH);
- }
- }
-
- public IStore createStore(String repoName)
- {
- IMappingStrategy mappingStrategy = createMappingStrategy();
- mappingStrategy.setProperties(createMappingStrategyProperties());
-
- IDBAdapter dbAdapter = createDBAdapter();
-
- DataSource dataSource = createDataSource(repoName);
- IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);
-
- return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider);
}
@Override
- public void setUp() throws Exception
- {
- CDODBUtil.prepareContainer(IPluginContainer.INSTANCE);
- super.setUp();
- }
-
- protected Map<String, String> createMappingStrategyProperties()
- {
- Map<String, String> props = new HashMap<String, String>();
- props.put(IMappingStrategy.PROP_QUALIFIED_NAMES, "true");
- props.put(CDODBUtil.PROP_COPY_ON_BRANCH, Boolean.toString(copyOnBranch));
- return props;
- }
-
- protected IMappingStrategy createMappingStrategy()
- {
- return CDODBUtil.createHorizontalMappingStrategy(isSupportingAudits(), isSupportingBranches(), withRanges);
- }
-
- @Override
- protected String getMappingStrategySpecialization()
- {
- return (withRanges ? "-ranges" : "") + (copyOnBranch ? "-copy" : "");
- }
-
protected IDBAdapter createDBAdapter()
{
return new H2Adapter();
}
+ @Override
protected DataSource createDataSource(String repoName)
{
if (reusableFolder == null)
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlOfflineConfig.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlOfflineConfig.java new file mode 100644 index 0000000000..833103e028 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/MysqlOfflineConfig.java @@ -0,0 +1,156 @@ +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.db;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
+
+import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBAdapter;
+import org.eclipse.net4j.db.mysql.MYSQLAdapter;
+
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ * @author Stefan Winkler
+ */
+public class MysqlOfflineConfig extends DBOfflineConfig
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Instructions to test with MySQL: - create a mysql instance - set HOST to the host where the DB is running
+ * (listening on TCP) - set USER to a user who can create and drop databases (root, essentially) - set PASS to the
+ * password of the said user
+ */
+ public static final String HOST = "10.211.55.7:3306";
+
+ public static final String USER = "root";
+
+ public static final String PASS = null;
+
+ private transient DataSource setupDataSource;
+
+ private transient List<String> databases = new ArrayList<String>();
+
+ public MysqlOfflineConfig(boolean withRanges, boolean copyOnBranch, IDGenerationLocation idGenerationLocation)
+ {
+ super("MySqlOffline", withRanges, copyOnBranch, idGenerationLocation);
+ }
+
+ @Override
+ public void initCapabilities(Set<String> capabilities)
+ {
+ super.initCapabilities(capabilities);
+ capabilities.add(MysqlConfig.DB_ADAPTER_NAME);
+ }
+
+ @Override
+ protected IDBAdapter createDBAdapter()
+ {
+ return new MYSQLAdapter();
+ }
+
+ @Override
+ protected DataSource createDataSource(String repoName)
+ {
+ MysqlDataSource ds = new MysqlDataSource();
+
+ initDatabase("test_" + repoName);
+
+ ds.setUrl("jdbc:mysql://" + HOST + "/test_" + repoName);
+ ds.setUser(USER);
+ if (PASS != null)
+ {
+ ds.setPassword(PASS);
+ }
+
+ return ds;
+ }
+
+ private void initDatabase(String dbName)
+ {
+ dropDatabase(dbName);
+ Connection connection = null;
+ Statement stmt = null;
+
+ try
+ {
+ connection = getSetupDataSource().getConnection();
+ stmt = connection.createStatement();
+ stmt.execute("create database " + dbName);
+ }
+ catch (SQLException ignore)
+ {
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ DBUtil.close(connection);
+ }
+ }
+
+ private void dropDatabase(String dbName)
+ {
+ Connection connection = null;
+ Statement stmt = null;
+
+ try
+ {
+ connection = getSetupDataSource().getConnection();
+ stmt = connection.createStatement();
+ stmt.execute("DROP database " + dbName);
+ }
+ catch (SQLException ignore)
+ {
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ DBUtil.close(connection);
+ }
+ }
+
+ private DataSource getSetupDataSource()
+ {
+ if (setupDataSource == null)
+ {
+ MysqlDataSource ds = new MysqlDataSource();
+ ds.setUrl("jdbc:mysql://" + HOST + "/");
+ ds.setUser(USER);
+ if (PASS != null)
+ {
+ ds.setPassword(PASS);
+ }
+
+ setupDataSource = ds;
+ }
+
+ return setupDataSource;
+ }
+
+ protected void tearDownClean(String repoName)
+ {
+ for (String dbName : databases)
+ {
+ dropDatabase(dbName);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java index 60ac4fec6d..5e989f20eb 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java @@ -15,20 +15,28 @@ import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.lob.CDOBlob;
+import org.eclipse.emf.cdo.common.lob.CDOClob;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.server.syncing.OfflineClone;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
+import org.eclipse.emf.cdo.tests.bundle.OM;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model3.File;
+import org.eclipse.emf.cdo.tests.model3.Image;
import org.eclipse.emf.cdo.tests.util.TestListener;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.spi.cdo.DefaultCDOMerger;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@@ -425,4 +433,139 @@ public class OfflineTest extends AbstractSyncingTest CDOTransaction transaction = cloneSession.openTransaction();
transaction.commit();
}
+
+ public void _testDisconnectAndSyncBLOB() throws Exception
+ {
+ TestListener listener = new TestListener();
+ InternalRepository clone = getRepository();
+ waitForOnline(clone);
+
+ {
+ getOfflineConfig().stopMasterTransport();
+ waitForOffline(clone);
+
+ CDOSession masterSession = openSession("master");
+ CDOTransaction masterTransaction = masterSession.openTransaction();
+ CDOResource masterResource = masterTransaction.createResource("/master/resource");
+
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOBlob blob = new CDOBlob(inputStream);
+
+ Image image = getModel3Factory().createImage();
+ image.setWidth(320);
+ image.setHeight(200);
+ image.setData(blob);
+
+ masterResource.getContents().add(image);
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
+ masterTransaction.commit();
+ masterTransaction.close();
+ masterSession.addListener(listener);
+
+ getOfflineConfig().startMasterTransport();
+ waitForOnline(clone);
+ }
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource("/master/resource");
+
+ Image image = (Image)resource.getContents().get(0);
+
+ InputStream fromDisk = null;
+
+ try
+ {
+ fromDisk = OM.BUNDLE.getInputStream("copyright.txt");
+ IOUtil.equals(fromDisk, image.getData().getContents());
+ }
+ finally
+ {
+ IOUtil.close(fromDisk);
+ }
+ }
+
+ public void _testDisconnectAndSyncCLOB() throws Exception
+ {
+ TestListener listener = new TestListener();
+ InternalRepository clone = getRepository();
+ waitForOnline(clone);
+
+ {
+ getOfflineConfig().stopMasterTransport();
+ waitForOffline(clone);
+
+ CDOSession masterSession = openSession("master");
+ CDOTransaction masterTransaction = masterSession.openTransaction();
+ CDOResource masterResource = masterTransaction.createResource("/master/resource");
+
+ InputStream inputStream = null;
+
+ try
+ {
+ inputStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOClob clob = new CDOClob(new InputStreamReader(inputStream));
+
+ File file = getModel3Factory().createFile();
+ file.setName("copyright.txt");
+ file.setData(clob);
+
+ masterResource.getContents().add(file);
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
+ try
+ {
+ inputStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOClob clob = new CDOClob(new InputStreamReader(inputStream));
+
+ File file = getModel3Factory().createFile();
+ file.setName("plugin.properties");
+ file.setData(clob);
+
+ masterResource.getContents().add(file);
+ }
+ finally
+ {
+ IOUtil.close(inputStream);
+ }
+
+ masterTransaction.commit();
+ masterTransaction.close();
+ masterSession.addListener(listener);
+
+ getOfflineConfig().startMasterTransport();
+ waitForOnline(clone);
+ }
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource("/master/resource");
+
+ File file = (File)resource.getContents().get(0);
+
+ InputStream fromDisk = null;
+
+ try
+ {
+ fromDisk = OM.BUNDLE.getInputStream("copyright.txt");
+ IOUtil.equals(new InputStreamReader(fromDisk), file.getData().getContents());
+ }
+ finally
+ {
+ IOUtil.close(fromDisk);
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java index 683c91576c..2e4ef12037 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java @@ -14,9 +14,15 @@ package org.eclipse.net4j.db; import org.eclipse.net4j.util.io.ExtendedDataInput;
import org.eclipse.net4j.util.io.ExtendedDataOutput;
import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.io.TMPUtil;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
@@ -28,7 +34,7 @@ import java.sql.SQLException; /**
* Enumerates the SQL data types that are compatible with the DB framework.
- *
+ *
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
*/
@@ -511,11 +517,47 @@ public enum DBType long length = in.readLong();
if (length > 0)
{
+ reader = createFileReader(in, length);
+ }
+ else
+ {
reader = new Reader()
{
@Override
public int read(char[] cbuf, int off, int len) throws IOException
{
+ return -1;
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ // Do nothing
+ }
+ };
+ }
+
+ statement.setCharacterStream(column, reader, (int)length);
+ // reader.close();
+ return null;
+ }
+
+ private FileReader createFileReader(final ExtendedDataInput in, long length) throws IOException
+ {
+ FileWriter fw = null;
+
+ try
+ {
+ final File tempFile = TMPUtil.createTempFile("lob-", ".tmp");
+ tempFile.deleteOnExit();
+
+ fw = new FileWriter(tempFile);
+
+ Reader reader = new Reader()
+ {
+ @Override
+ public int read(char[] cbuf, int off, int len) throws IOException
+ {
int read = 0;
try
@@ -539,27 +581,23 @@ public enum DBType {
}
};
- }
- else
- {
- reader = new Reader()
- {
- @Override
- public int read(char[] cbuf, int off, int len) throws IOException
- {
- return -1;
- }
+ IOUtil.copyCharacter(reader, fw, length);
+
+ return new FileReader(tempFile)
+ {
@Override
public void close() throws IOException
{
+ super.close();
+ tempFile.delete();
}
};
}
-
- statement.setCharacterStream(column, reader, (int)length);
- reader.close();
- return null;
+ finally
+ {
+ IOUtil.close(fw);
+ }
}
},
@@ -824,11 +862,7 @@ public enum DBType try
{
out.writeLong(length);
- while (length-- > 0)
- {
- int b = stream.read();
- out.writeByte(b + Byte.MIN_VALUE);
- }
+ IOUtil.copyBinary(stream, new ExtendedDataOutput.Stream(out), length);
}
finally
{
@@ -851,32 +885,50 @@ public enum DBType long length = in.readLong();
InputStream value = null;
+ if (length > 0)
+ {
+ value = createFileInputStream(in, length);
+ }
+ else
+ {
+ value = new ByteArrayInputStream(new byte[0]);
+ }
+
+ statement.setBinaryStream(column, value, (int)length);
+
+ // XXX cannot close the input stream here, because
+ // it is still used in executeBatch() later.
+ // so maybe we could return it here and let the caller
+ // collect and close the streams.
+ return null;
+ }
+
+ private FileInputStream createFileInputStream(final ExtendedDataInput in, long length) throws IOException
+ {
+ FileOutputStream fos = null;
+
try
{
- if (length > 0)
+ final File tempFile = TMPUtil.createTempFile("lob-", ".tmp");
+ tempFile.deleteOnExit();
+
+ fos = new FileOutputStream(tempFile);
+ IOUtil.copyBinary(new ExtendedDataInput.Stream(in), fos, length);
+
+ return new FileInputStream(tempFile)
{
- value = new InputStream()
+ @Override
+ public void close() throws IOException
{
- @Override
- public int read() throws IOException
- {
- return in.readByte() - Byte.MIN_VALUE;
- }
- };
- }
- else
- {
- value = new ByteArrayInputStream(new byte[0]);
- }
-
- statement.setBinaryStream(column, value, (int)length);
+ super.close();
+ tempFile.delete();
+ }
+ };
}
finally
{
- IOUtil.close(value);
+ IOUtil.close(fos);
}
-
- return null;
}
};
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java index fd731d5f04..e2384fe9fb 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java @@ -168,7 +168,6 @@ public interface ExtendedDataInput extends DataInput * @author Eike Stepper
* @since 2.0
*/
- @Deprecated
public static class Stream extends InputStream
{
private ExtendedDataInput delegate;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java index fdf50ae47d..7b6feaa3e5 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java @@ -146,7 +146,6 @@ public interface ExtendedDataOutput extends DataOutput * @author Eike Stepper
* @since 2.0
*/
- @Deprecated
public static class Stream extends OutputStream
{
private ExtendedDataOutput delegate;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java index 935a4dbbd1..359a79e9cc 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java @@ -447,26 +447,20 @@ public final class IOUtil */
public static void copyBinary(InputStream inputStream, OutputStream outputStream, long size) throws IOException
{
- if (!(inputStream instanceof BufferedInputStream) && !(inputStream instanceof ByteArrayInputStream))
- {
- inputStream = new BufferedInputStream(inputStream);
- }
-
- if (!(outputStream instanceof BufferedOutputStream) && !(outputStream instanceof ByteArrayOutputStream))
- {
- outputStream = new BufferedOutputStream(outputStream);
- }
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
while (size > 0L)
{
- int b = inputStream.read();
- if (b == EOF)
+ int bytesToCopy = (int)Math.min(size, buffer.length);
+
+ int bytesRead = inputStream.read(buffer, 0, bytesToCopy);
+ if (bytesRead < bytesToCopy)
{
throw new EOFException();
}
- outputStream.write(b);
- --size;
+ outputStream.write(buffer, 0, bytesToCopy);
+ size -= bytesRead;
}
outputStream.flush();
@@ -504,26 +498,20 @@ public final class IOUtil */
public static void copyCharacter(Reader reader, Writer writer, long size) throws IOException
{
- if (!(reader instanceof BufferedReader) && !(reader instanceof CharArrayReader))
- {
- reader = new BufferedReader(reader);
- }
-
- if (!(writer instanceof BufferedWriter) && !(writer instanceof CharArrayWriter))
- {
- writer = new BufferedWriter(writer);
- }
+ char[] buffer = new char[DEFAULT_BUFFER_SIZE];
while (size > 0L)
{
- int c = reader.read();
- if (c == EOF)
+ int charsToCopy = (int)Math.min(size, buffer.length);
+
+ int charsRead = reader.read(buffer, 0, charsToCopy);
+ if (charsRead < charsToCopy)
{
throw new EOFException();
}
- writer.write(c);
- --size;
+ writer.write(buffer, 0, charsRead);
+ size -= charsRead;
}
writer.flush();
@@ -796,6 +784,35 @@ public final class IOUtil }
}
+ /**
+ * @since 3.2
+ */
+ public static boolean equals(Reader reader1, Reader reader2) throws IORuntimeException
+ {
+ try
+ {
+ for (;;)
+ {
+ int char1 = reader1.read();
+ int char2 = reader2.read();
+
+ if (char1 != char2)
+ {
+ return false;
+ }
+
+ if (char1 == -1)// Implies char2 == -1
+ {
+ return true;
+ }
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
public static boolean equals(File file1, File file2) throws IORuntimeException
{
if (file1.length() != file2.length())
|