private void implicitRelease( Company company, LockType type, CDOTransaction tx, TestListener2 controlViewListener, boolean mustReceiveNotifications) throws CommitException { CDOViewLocksChangedEvent e; CDOObject cdoCompany = CDOUtil.getCDOObject(company); company.setName(company.getName() + "x"); // Make name field dirty cdoCompany.cdoWriteLock().lock(); if (mustReceiveNotifications) { controlViewListener.waitFor(1); e = (CDOViewLocksChangedEvent) controlViewListener.getEvents().get(0); assertSame(Operation.LOCK, e.getOperation()); assertSame(LockType.WRITE, e.getLockType()); } tx.commit(); if (mustReceiveNotifications) { controlViewListener.waitFor(2); e = (CDOViewLocksChangedEvent) controlViewListener.getEvents().get(1); assertSame(Operation.UNLOCK, e.getOperation()); assertNull(e.getLockType()); } if (!mustReceiveNotifications) { assertEquals(0, controlViewListener.getEvents().size()); } }
@Requires(IRepositoryConfig.CAPABILITY_AUDITING) public void testReloadingRevisions() throws Exception { final String RESOURCE_NAME = "resource"; Set<CDOID> ids = new HashSet<CDOID>(); long timeStampOfHoleCommit; CDOSession initialSession = openSession(); { // create model history CDOTransaction openTransaction = initialSession.openTransaction(); CDOResource resource = openTransaction.getOrCreateResource(getResourcePath(RESOURCE_NAME)); // creating initial commit Company createdCompany = getModel1Factory().createCompany(); createdCompany.setName("CompanyTesting"); createdCompany.setCity("City"); createdCompany.setStreet("Street"); resource.getContents().add(createdCompany); openTransaction.commit(); // collect id's for (TreeIterator<EObject> allContents = resource.getAllContents(); allContents.hasNext(); ) { CDOObject next = CDOUtil.getCDOObject(allContents.next()); ids.add(next.cdoID()); } // making holes - detaching List<EObject> contents = new ArrayList<EObject>(resource.getContents()); for (int i = 0; i < contents.size(); i++) { EcoreUtil.delete(contents.get(i), true); } timeStampOfHoleCommit = openTransaction.commit().getTimeStamp(); } // check when locally cached elements are availabe checkRevisionsOnGivenSession(ids, timeStampOfHoleCommit, 2, initialSession); // turn of revision download by timestamp checkRevisionsOnGivenSession(ids, -1, 2, initialSession); initialSession.close(); checkRevisions(ids, timeStampOfHoleCommit, 2); // turn of revision download by timestamp checkRevisions(ids, -1, 2); // clear caches clearCache(getRepository().getRevisionManager()); checkRevisions(ids, timeStampOfHoleCommit, 2); // turn of revision download by timestamp clearCache(getRepository().getRevisionManager()); checkRevisions(ids, -1, 2); }
/** See bug 315409. */ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING) public void _testInvalidationWithDeltas_SubBranch() throws Exception { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); Company company = getModel1Factory().createCompany(); company.setName("main-v1"); CDOResource resource = transaction.createResource(getResourcePath("/test1")); resource.getContents().add(company); transaction.commit(); company.setName("main-v2"); transaction.commit(); CDOBranch subBranch = transaction.getBranch().createBranch("SUB_BRANCH"); transaction.setBranch(subBranch); CDOView view = session.openView(subBranch); view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL); Company company2 = view.getObject(company); company2.eAdapters().add(new AdapterImpl()); company.setName("sub-v1"); commitAndSync(transaction, view); CDORevision revision2 = CDOUtil.getCDOObject(company2).cdoRevision(); assertEquals(1, revision2.getVersion()); assertEquals(transaction.getBranch(), revision2.getBranch()); assertEquals(transaction.getLastCommitTime(), revision2.getTimeStamp()); company.setName("sub-v2"); commitAndSync(transaction, view); revision2 = CDOUtil.getCDOObject(company2).cdoRevision(); assertEquals(2, revision2.getVersion()); assertEquals(transaction.getBranch(), revision2.getBranch()); assertEquals(transaction.getLastCommitTime(), revision2.getTimeStamp()); }
/** See bug 315409. */ public void testInvalidationWithDeltas_SameBranch() throws Exception { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOView view = session.openView(); Company company = getModel1Factory().createCompany(); company.setName("main-v1"); CDOResource resource = transaction.createResource(getResourcePath("/test1")); resource.getContents().add(company); commitAndSync(transaction, view); company.setName("main-v2"); commitAndSync(transaction, view); view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL); Company company2 = view.getObject(company); company2.eAdapters().add(new AdapterImpl()); company.setName("main-v3"); commitAndSync(transaction, view); CDORevision revision2 = CDOUtil.getCDOObject(company2).cdoRevision(); assertEquals(3, revision2.getVersion()); assertEquals(transaction.getBranch(), revision2.getBranch()); assertEquals(transaction.getLastCommitTime(), revision2.getTimeStamp()); company.setName("main-v4"); commitAndSync(transaction, view); revision2 = CDOUtil.getCDOObject(company2).cdoRevision(); assertEquals(4, revision2.getVersion()); assertEquals(transaction.getBranch(), revision2.getBranch()); assertEquals(transaction.getLastCommitTime(), revision2.getTimeStamp()); }
public void testNotificationChain() throws Exception { msg("Opening session"); final CDOSession session = openSession(); // ************************************************************* // msg("Creating category1"); final Category category1A = getModel1Factory().createCategory(); category1A.setName("category1"); msg("Creating company"); final Company companyA = getModel1Factory().createCompany(); msg("Adding categories"); companyA.getCategories().add(category1A); msg("Opening transaction"); final CDOTransaction transaction = session.openTransaction(); transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL); msg("Creating resource"); final CDOResource resourceA = transaction.createResource(getResourcePath("/test1")); msg("Adding company"); resourceA.getContents().add(companyA); msg("Committing"); transaction.commit(); final TestAdapter adapter = new TestAdapter(); companyA.eAdapters().add(adapter); // ************************************************************* // msg("Opening view"); final CDOSession session2 = openSession(); final CDOTransaction transaction2 = session2.openTransaction(); final Company company1B = (Company) CDOUtil.getEObject( transaction2.getObject(CDOUtil.getCDOObject(companyA).cdoID(), true)); msg("Changing name"); company1B.setName("TEST1"); company1B.setCity("CITY1"); final Category category2B = getModel1Factory().createCategory(); company1B.getCategories().add(category2B); assertEquals(0, adapter.getNotifications().length); msg("Committing"); transaction2.commit(); msg("Checking after commit"); new PollingTimeOuter() { @Override protected boolean successful() { return adapter.getNotifications().length == 3; } }.assertNoTimeOut(); int count = 0; for (Notification notification : adapter.getNotifications()) { CDODeltaNotification cdoNotification = (CDODeltaNotification) notification; if (adapter.getNotifications().length - 1 == count) { assertEquals(false, cdoNotification.hasNext()); } else { assertEquals(true, cdoNotification.hasNext()); } if (notification.getFeature() == getModel1Package().getCategory_Name()) { assertEquals(Notification.SET, notification.getEventType()); assertEquals("TEST1", notification.getNewStringValue()); } else if (notification.getFeature() == getModel1Package().getAddress_City()) { assertEquals(Notification.SET, notification.getEventType()); assertEquals("CITY1", notification.getNewStringValue()); } else if (notification.getFeature() == getModel1Package().getCompany_Categories()) { assertEquals(Notification.ADD, notification.getEventType()); assertEquals(1, notification.getPosition()); assertEquals( transaction.getObject(CDOUtil.getCDOObject(category2B).cdoID(), true), notification.getNewValue()); } else { assertEquals(false, false); } count++; } }
public void testSeparateSession_CUSTOM() throws Exception { CDOIDFilterChangeSubscriptionPolicy customPolicy = new CDOIDFilterChangeSubscriptionPolicy(); msg("Opening session"); final CDOSession session = openSession(); // ************************************************************* // msg("Creating category1"); final Category category1A = getModel1Factory().createCategory(); category1A.setName("category1"); msg("Creating company"); final Company companyA = getModel1Factory().createCompany(); msg("Adding categories"); companyA.getCategories().add(category1A); msg("Opening transaction"); final CDOTransaction transaction = session.openTransaction(); transaction.options().addChangeSubscriptionPolicy(customPolicy); msg("Creating resource"); final CDOResource resourceA = transaction.createResource(getResourcePath("/test1")); msg("Adding company"); resourceA.getContents().add(companyA); msg("Committing"); transaction.commit(); final TestAdapter adapter = new TestAdapter(); customPolicy.getCdoIDs().add(CDOUtil.getCDOObject(category1A).cdoID()); category1A.eAdapters().add(adapter); companyA.eAdapters().add(adapter); // ************************************************************* // msg("Opening view"); final CDOSession session2 = openSession(); final CDOTransaction transaction2 = session2.openTransaction(); final Category category1B = (Category) CDOUtil.getEObject( transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true)); final Company company1B = (Company) CDOUtil.getEObject( transaction2.getObject(CDOUtil.getCDOObject(companyA).cdoID(), true)); msg("Changing name"); category1B.setName("CHANGED NAME"); company1B.setName("TEST1"); assertEquals(0, adapter.getNotifications().length); msg("Committing"); transaction2.commit(); msg("Checking after commit"); new PollingTimeOuter() { @Override protected boolean successful() { return adapter.getNotifications().length == 1; } }.assertNoTimeOut(); // Switching policy to the other transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL); adapter.clearNotifications(); msg("Changing name"); category1B.setName("CHANGED NAME_VERSION 2"); company1B.setName("TEST2"); assertEquals(0, adapter.getNotifications().length); msg("Committing"); transaction2.commit(); msg("Checking after commit"); new PollingTimeOuter() { @Override protected boolean successful() { return adapter.getNotifications().length == 2; } }.assertNoTimeOut(); }