summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-14 04:59:54 (EDT)
committerEike Stepper2007-09-14 04:59:54 (EDT)
commitf72d60fd80f85c6c2003b51836199273da8809e7 (patch)
treea14663ebd688541deb82366647c256eaec7e7167
parent0bac957dfb02b9c46de17effb80b49f82215493b (diff)
downloadcdo-f72d60fd80f85c6c2003b51836199273da8809e7.zip
cdo-f72d60fd80f85c6c2003b51836199273da8809e7.tar.gz
cdo-f72d60fd80f85c6c2003b51836199273da8809e7.tar.bz2
[202064] More client-side intelligence (SmartReadAhead Thread)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202064
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContentAdapterTest.java154
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java6
2 files changed, 157 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContentAdapterTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContentAdapterTest.java
new file mode 100644
index 0000000..6ceb533
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContentAdapterTest.java
@@ -0,0 +1,154 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.emf.internal.cdo.CDOSessionImpl;
+import org.eclipse.emf.internal.cdo.CDOTransactionImpl;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class ContentAdapterTest extends AbstractCDOTest
+{
+ public void testContentAdapterUsingCDOResource() throws Exception
+ {
+ final boolean notified[] = new boolean[1];
+ EContentAdapter contentAdapter = new EContentAdapter()
+ {
+ @Override
+ public void notifyChanged(Notification notification)
+ {
+ super.notifyChanged(notification);
+ notified[0] = true;
+ }
+
+ @Override
+ protected boolean resolve()
+ {
+ return false;
+ }
+ };
+
+ CDOID supplierID = null;
+
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction(new ResourceSetImpl());
+
+ CDOResource resource = transaction.createResource("/test2");
+ resource.eAdapters().add(contentAdapter);
+
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ resource.getContents().add(supplier);
+ notified[0] = false;
+
+ // contentAdapter should receive notification
+ supplier.setName("HELLO");
+
+ assertEquals(true, notified[0]);
+ supplierID = supplier.cdoID();
+ transaction.commit();
+ supplierID = supplier.cdoID();
+
+ transaction.close();
+ session.close();
+ }
+
+ {
+ CDOSessionImpl session = (CDOSessionImpl)openModel1Session();
+
+ CDOFetchRuleManagerInfo info = new CDOFetchRuleManagerInfo();
+ session.getRevisionManager().setRuleManager(info);
+
+ CDOTransactionImpl transaction = session.openTransaction(new ResourceSetImpl());
+ CDOResource resource = transaction.getResource("/test2");
+
+ // I don't want to fetch my objects!!
+ resource.eAdapters().add(contentAdapter);
+
+ // By adding an adapter, we shouldn`t fetch objects
+ assertEquals(false, info.getFetchedIDs().contains(supplierID));
+
+ Supplier supplier = (Supplier)transaction.getObject(supplierID);
+ notified[0] = false;
+
+ // contentAdapter should receive notification
+ supplier.setName("HELLO");
+
+ // Should have been notified!!
+ assertEquals(true, notified[0]);
+
+ transaction.commit();
+ transaction.close();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class CDOFetchRuleManagerInfo implements CDOFetchRuleManager
+ {
+ private Set<CDOID> fetchedIDs = new HashSet<CDOID>();
+
+ public CDOFetchRuleManagerInfo()
+ {
+ }
+
+ public CDOID getContext()
+ {
+ return CDOIDNull.NULL;
+ }
+
+ public void clear()
+ {
+ fetchedIDs.clear();
+ }
+
+ public Set<CDOID> getFetchedIDs()
+ {
+ return fetchedIDs;
+ }
+
+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
+ {
+ // accumulate changes
+ for (CDOID id : ids)
+ {
+ fetchedIDs.add(id);
+ }
+
+ return null;
+ }
+
+ public int getLoadRevisionCollectionChunkSize()
+ {
+ return 0;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
index bb39a8d..6e2b168 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
@@ -19,15 +19,15 @@ import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
import org.eclipse.emf.cdo.tests.model1.Supplier;
import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.net4j.IBufferHandler;
-import org.eclipse.net4j.IChannel;
-
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.net4j.IBufferHandler;
+import org.eclipse.net4j.IChannel;
+
import java.util.Date;
/**