diff options
author | Roberto E. Escobar | 2012-01-14 00:49:01 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2012-01-14 00:49:01 +0000 |
commit | d79ca96b74c490ce62d37714336170cb07d9e738 (patch) | |
tree | f033e57b6b38b302a849a2528146f301e2810046 | |
parent | a4ae44edbc3863f22d9d45c8eb35ed095f3e6491 (diff) | |
download | org.eclipse.osee-d79ca96b74c490ce62d37714336170cb07d9e738.tar.gz org.eclipse.osee-d79ca96b74c490ce62d37714336170cb07d9e738.tar.xz org.eclipse.osee-d79ca96b74c490ce62d37714336170cb07d9e738.zip |
bug[ats_6WFC6]: Allow multiple skynetTransactions without artifact overlaps
46 files changed, 1166 insertions, 447 deletions
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java index cf2ec1cb5cb..e2671640344 100644 --- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java @@ -368,23 +368,31 @@ public class AtsTestUtil { reset(name); } + private static void delete(SkynetTransaction transaction, Artifact artifact) throws OseeCoreException { + if (artifact != null) { + artifact.deleteAndPersist(transaction); + } + } + /** * Cleanup all artifacts and confirm that ArtifactCache has no dirty artifacts. Should be called at beginning at end * of each test. */ public static void cleanup() throws OseeCoreException { - SkynetTransaction transaction = + SkynetTransaction transaction1 = TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(), AtsTestUtil.class.getSimpleName() + " - cleanup 1"); - if (peerRevArt != null) { - peerRevArt.deleteAndPersist(transaction); - } - if (decRevArt != null) { - decRevArt.deleteAndPersist(transaction); - } - if (taskArt != null) { - taskArt.deleteAndPersist(transaction); - } + delete(transaction1, peerRevArt); + delete(transaction1, decRevArt); + delete(transaction1, taskArt); + delete(transaction1, teamArt2); + delete(transaction1, actionArt); + delete(transaction1, actionArt2); + transaction1.execute(); + if (teamArt != null) { + SkynetTransaction transaction2 = + TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(), AtsTestUtil.class.getSimpleName() + " - cleanup 2"); + if (teamArt.getWorkingBranch() != null) { Result result = AtsBranchManagerCore.deleteWorkingBranch(teamArt, true); if (result.isFalse()) { @@ -392,42 +400,26 @@ public class AtsTestUtil { } } for (TaskArtifact taskArt : teamArt.getTaskArtifacts()) { - taskArt.deleteAndPersist(transaction); + taskArt.deleteAndPersist(transaction2); } for (AbstractReviewArtifact revArt : ReviewManager.getReviews(teamArt)) { - revArt.deleteAndPersist(transaction); + revArt.deleteAndPersist(transaction2); } - teamArt.deleteAndPersist(transaction); - } - if (teamArt2 != null) { - teamArt2.deleteAndPersist(transaction); - } - if (actionArt != null) { - actionArt.deleteAndPersist(transaction); - } - if (actionArt2 != null) { - actionArt2.deleteAndPersist(transaction); - } - transaction.execute(); - transaction = - TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(), AtsTestUtil.class.getSimpleName() + " - cleanup 2"); - if (testAi != null) { - testAi.deleteAndPersist(transaction); - } - if (testAi2 != null) { - testAi2.deleteAndPersist(transaction); - } - if (verArt1 != null) { - verArt1.deleteAndPersist(transaction); - } - if (verArt2 != null) { - verArt2.deleteAndPersist(transaction); + delete(transaction2, teamArt); + transaction2.execute(); } - if (teamDef != null) { - teamDef.deleteAndPersist(transaction); - } - transaction.execute(); + + SkynetTransaction transaction3 = + TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(), AtsTestUtil.class.getSimpleName() + " - cleanup 3"); + + delete(transaction3, testAi); + delete(transaction3, testAi2); + delete(transaction3, verArt1); + delete(transaction3, verArt2); + delete(transaction3, teamDef); + + transaction3.execute(); clearCaches(); diff --git a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsActionTest.java b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsActionTest.java index 62bebe14ba7..27e50e6e74c 100644 --- a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsActionTest.java +++ b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsActionTest.java @@ -28,6 +28,6 @@ public class DeletePurgeAtsArtifactsActionTest extends AbstractAtsActionTest { @Override public DeletePurgeAtsArtifactsAction createAction() throws OseeCoreException { AtsTestUtil.cleanupAndReset(getClass().getSimpleName()); - return new DeletePurgeAtsArtifactsAction(AtsTestUtil.getSelectedAtsArtifactsForTeamWf()); + return new DeletePurgeAtsArtifactsAction(AtsTestUtil.getSelectedAtsArtifactsForTeamWf(), true); } } diff --git a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/column/CategoryColumnTest.java b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/column/CategoryColumnTest.java index c46ca00bfe6..836007a5aed 100644 --- a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/column/CategoryColumnTest.java +++ b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/column/CategoryColumnTest.java @@ -96,7 +96,8 @@ public class CategoryColumnTest { Assert.assertTrue(actionArtStr.contains("that")); Assert.assertTrue(actionArtStr.contains("the other")); - transaction = TransactionManager.createTransaction(AtsUtil.getAtsBranch(), CategoryColumnTest.class.getSimpleName()); + transaction = + TransactionManager.createTransaction(AtsUtil.getAtsBranch(), CategoryColumnTest.class.getSimpleName()); codeArt.deleteAttributes(AtsAttributeTypes.Category1); codeArt.persist(transaction); reqArt.deleteSoleAttribute(AtsAttributeTypes.Category1); diff --git a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsForceAssigneesToTeamLeadsStateItemTest.java b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsForceAssigneesToTeamLeadsStateItemTest.java index 1ab28af798f..918e1592949 100644 --- a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsForceAssigneesToTeamLeadsStateItemTest.java +++ b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsForceAssigneesToTeamLeadsStateItemTest.java @@ -52,7 +52,8 @@ public class AtsForceAssigneesToTeamLeadsStateItemTest { assertFalse("Test should not be run in production db", AtsUtil.isProductionDb()); if (teamArt == null) { - SkynetTransaction transaction = TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); + SkynetTransaction transaction = + TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); teamArt = DemoTestUtil.createSimpleAction(getClass().getSimpleName(), transaction); transaction.execute(); } @@ -99,7 +100,8 @@ public class AtsForceAssigneesToTeamLeadsStateItemTest { // make call to state item that should set options based on artifact's attribute value AtsForceAssigneesToTeamLeadsStateItem stateItem = new AtsForceAssigneesToTeamLeadsStateItem(); - SkynetTransaction transaction = TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); + SkynetTransaction transaction = + TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); stateItem.transitioned(teamArt, fromState, toState, Arrays.asList((IBasicUser) UserManager.getUser()), transaction); transaction.execute(); diff --git a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsPeerToPeerReviewReviewStateItemTest.java b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsPeerToPeerReviewReviewStateItemTest.java index cef8b67e352..4f0201a9bea 100644 --- a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsPeerToPeerReviewReviewStateItemTest.java +++ b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/editor/stateItem/AtsPeerToPeerReviewReviewStateItemTest.java @@ -48,7 +48,8 @@ public class AtsPeerToPeerReviewReviewStateItemTest { if (peerRevArt == null) { // setup fake review artifact with decision options set - SkynetTransaction transaction = TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); + SkynetTransaction transaction = + TransactionManager.createTransaction(AtsUtil.getAtsBranch(), getClass().getSimpleName()); peerRevArt = PeerToPeerReviewManager.createNewPeerToPeerReview(null, getClass().getName(), "", transaction); peerRevArt.setName(getClass().getSimpleName()); peerRevArt.persist(transaction); diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsAction.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsAction.java index ae507978af3..b28930b3633 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsAction.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/actions/DeletePurgeAtsArtifactsAction.java @@ -25,17 +25,19 @@ public class DeletePurgeAtsArtifactsAction extends AbstractAtsAction { private static final String MSG = "Delete/Purge Ats Artifact(s)"; private final ISelectedAtsArtifacts selectedAtsArtifacts; private boolean prompt = true; + private final boolean executeInCurrentThread; - public DeletePurgeAtsArtifactsAction(ISelectedAtsArtifacts selectedAtsArtifacts) { + public DeletePurgeAtsArtifactsAction(ISelectedAtsArtifacts selectedAtsArtifacts, boolean executeInCurrentThread) { super(MSG, ImageManager.getImageDescriptor(FrameworkImage.ARTIFACT_EDITOR)); this.selectedAtsArtifacts = selectedAtsArtifacts; setToolTipText(getText()); + this.executeInCurrentThread = executeInCurrentThread; } @Override public void runWithException() throws OseeCoreException { - AtsDeleteManager.handleDeletePurgeAtsObject(selectedAtsArtifacts.getSelectedSMAArtifacts(), false, - (prompt ? DeleteOption.Prompt : null)); + AtsDeleteManager.handleDeletePurgeAtsObject(selectedAtsArtifacts.getSelectedSMAArtifacts(), + executeInCurrentThread, (prompt ? DeleteOption.Prompt : null)); } public void setPrompt(boolean prompt) { diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/SMAOperationsSection.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/SMAOperationsSection.java index cc7d9abf697..ae3ad781e83 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/SMAOperationsSection.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/SMAOperationsSection.java @@ -187,7 +187,7 @@ public class SMAOperationsSection extends SectionPart { sectionBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); new XButtonViaAction(new RefreshDirtyAction(editor)).createWidgets(sectionBody, 2); - new XButtonViaAction(new DeletePurgeAtsArtifactsAction(editor)).createWidgets(sectionBody, 2); + new XButtonViaAction(new DeletePurgeAtsArtifactsAction(editor, false)).createWidgets(sectionBody, 2); if (ShowBranchChangeDataAction.isApplicable(editor.getAwa())) { new XButtonViaAction(new ShowBranchChangeDataAction(editor.getAwa())).createWidgets(sectionBody, 2); } diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewer.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewer.java index da9c64c2e79..c81e1caf994 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewer.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewer.java @@ -133,7 +133,7 @@ public class WorldXViewer extends XViewer implements ISelectedAtsArtifacts, IPer convertActionableItemsAction = new ConvertActionableItemsAction(this); favoritesAction = new FavoriteAction(this); subscribedAction = new SubscribedAction(this); - deletePurgeAtsObjectAction = new DeletePurgeAtsArtifactsAction(this); + deletePurgeAtsObjectAction = new DeletePurgeAtsArtifactsAction(this, false); emailAction = new EmailActionAction(this); editStatusAction = new EditStatusAction(this, this, this, true); editAssigneeAction = new EditAssigneeAction(this, this); diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/CoveragePackageImportTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/CoveragePackageImportTest.java index 34ef6d0439c..aa247780da1 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/CoveragePackageImportTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/CoveragePackageImportTest.java @@ -100,6 +100,10 @@ public class CoveragePackageImportTest { } } + private String getComment(int index) { + return String.format("%s.%s %d", CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName(), index); + } + @Test public void testImport1() throws Exception { CoverageImport1TestBlam coverageImport1TestBlam = new CoverageImport1TestBlam(); @@ -228,9 +232,11 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); - store.getArtifact(false).persist(transaction); + Artifact artifactX = store.getArtifact(false); + artifactX.persist(transaction); // Test Load of Coverage Package Artifact artifact = @@ -282,7 +288,6 @@ public class CoveragePackageImportTest { Assert.assertTrue(mergeManager.getMergeItems(null).iterator().next() instanceof MessageMergeItem); } - @Ignore @Test // Re-import two new Coverage Unit files // com.screenA.ComScrnButton3 and epu.PowerUnit3 @@ -343,7 +348,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -381,8 +387,8 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); SkynetTransaction testLoadCovPackageTransaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + String.format("%s.%s", CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); if (testWithDb) { // Test Load of Coverage Package Artifact artifact = @@ -483,7 +489,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -543,8 +550,8 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); SkynetTransaction testLoadTransaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + String.format("%s.%s", CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); if (testWithDb) { // Test Load of Coverage Package Artifact artifact = @@ -625,7 +632,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -669,22 +677,17 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - - transaction.execute(); } - // Look at file contents for NavigationButton.setImage and make sure only one coverageitem exists + // Look at file contents for NavigationButton.setImage and make sure only one coverage item exists CoverageUnit coverageUnit = (CoverageUnit) CoverageTestUtil.getFirstCoverageByNameEquals(coveragePackage, "NavigationButton1.java"); Assert.assertNotNull(coverageUnit); @@ -752,7 +755,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -788,19 +792,14 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - - transaction.execute(); } // Get and store off coverage unit to delete so can confirm deletion occurred @@ -892,7 +891,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -954,20 +954,14 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); - // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - - transaction.execute(); } // Get and store off coverage unit to delete so can confirm deletion occurred @@ -1064,7 +1058,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -1151,18 +1146,14 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - transaction.execute(); } // Get and store off coverage unit to delete so can confirm deletion occurred @@ -1253,7 +1244,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -1308,18 +1300,14 @@ public class CoveragePackageImportTest { Assert.assertNotNull(coverageImport); if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - transaction.execute(); } CoverageUnit navigationButton2Unit = @@ -1400,7 +1388,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); @@ -1457,23 +1446,15 @@ public class CoveragePackageImportTest { coverageImport = coverageImport10TestBlam.run(null); Assert.assertNotNull(coverageImport); - SkynetTransaction importingTransaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), - CoveragePackageImportTest.class.getSimpleName() + ".testImport10"); - if (testWithDb) { - SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), - CoveragePackageImportTest.class.getSimpleName() + ".testImport10"); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); CoverageTestUtil.registerAsTestArtifact(artifact); - artifact.persist(transaction); + artifact.persist(getComment(1)); OseeCoveragePackageStore packageStore = new OseeCoveragePackageStore(artifact); Assert.assertNotNull(packageStore.getArtifact(false)); coveragePackage = packageStore.getCoveragePackage(); - transaction.execute(); } // Change NavigateButton1.java methods to insert user disposition item as Coverage_Method for 2 items @@ -1483,8 +1464,8 @@ public class CoveragePackageImportTest { // reload coverage package from store if (testWithDb) { SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), String.format("%s.%s", - CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + String.format("%s.%s", CoveragePackageImportTest.class.getSimpleName(), testName.getMethodName())); // Test Load of Coverage Package Artifact artifact = ArtifactQuery.getArtifactFromId(coveragePackage.getGuid(), CoverageTestUtil.getTestBranch()); @@ -1573,7 +1554,8 @@ public class CoveragePackageImportTest { // Test Persist of CoveragePackage OseeCoverageStore store = OseeCoveragePackageStore.get(coveragePackage, CoverageTestUtil.getTestBranch()); SkynetTransaction transaction = - TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Coverage Package Save " + testName.getMethodName()); + TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), + "Coverage Package Save " + testName.getMethodName()); store.save(transaction, getTestCoveragePackageEvent()); store.getArtifact(false).persist(transaction); diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageItemTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageItemTest.java index fff946c758f..8645f3a723b 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageItemTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageItemTest.java @@ -10,11 +10,6 @@ *******************************************************************************/ package org.eclipse.osee.coverage.model; -import org.eclipse.osee.coverage.model.CoverageItem; -import org.eclipse.osee.coverage.model.CoverageOptionManager; -import org.eclipse.osee.coverage.model.CoverageOptionManagerDefault; -import org.eclipse.osee.coverage.model.CoverageUnit; -import org.eclipse.osee.coverage.model.SimpleTestUnitProvider; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.junit.Assert; diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageOptionManagerTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageOptionManagerTest.java index 8633cb399b8..b2250cc1038 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageOptionManagerTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageOptionManagerTest.java @@ -10,10 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.coverage.model; -import org.eclipse.osee.coverage.model.CoverageOption; -import org.eclipse.osee.coverage.model.CoverageOptionManager; import org.eclipse.osee.coverage.model.CoverageOptionManager.EnabledOption; -import org.eclipse.osee.coverage.model.CoverageOptionManagerDefault; import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.junit.Assert; import org.junit.Test; diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageUnitTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageUnitTest.java index 9196db85ded..eef303b2170 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageUnitTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/CoverageUnitTest.java @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.osee.coverage.model; -import org.eclipse.osee.coverage.model.CoverageItem; -import org.eclipse.osee.coverage.model.CoverageOptionManager; -import org.eclipse.osee.coverage.model.CoverageUnit; -import org.eclipse.osee.coverage.model.SimpleCoverageUnitFileContentsProvider; import org.eclipse.osee.coverage.util.CoverageTestUtil; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.GUID; diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/SimpleTestUnitProviderTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/SimpleTestUnitProviderTest.java index 1f2bb0a5ed1..e34aa6e8960 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/SimpleTestUnitProviderTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/model/SimpleTestUnitProviderTest.java @@ -10,12 +10,8 @@ *******************************************************************************/ package org.eclipse.osee.coverage.model; -import org.junit.Assert; -import org.eclipse.osee.coverage.model.CoverageItem; -import org.eclipse.osee.coverage.model.CoverageOptionManager; -import org.eclipse.osee.coverage.model.CoverageOptionManagerDefault; -import org.eclipse.osee.coverage.model.SimpleTestUnitProvider; import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/navigate/CoverageTestNavigateViews.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/navigate/CoverageTestNavigateViews.java index 9ca2c752928..678c5cbaac4 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/navigate/CoverageTestNavigateViews.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/navigate/CoverageTestNavigateViews.java @@ -24,7 +24,6 @@ import org.eclipse.osee.coverage.import08.CoveragePackage1Import8; import org.eclipse.osee.coverage.import09.CoveragePackage1Import9; import org.eclipse.osee.coverage.import10.CoveragePackage1Import10; import org.eclipse.osee.coverage.import10.CoveragePackage1Import10a; -import org.eclipse.osee.coverage.navigate.ICoverageNavigateItem; import org.eclipse.osee.coverage.package1.CoveragePackage1; import org.eclipse.osee.framework.ui.plugin.OseeUiActivator; import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem; diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/ArtifactTestUnitStoreTest.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/ArtifactTestUnitStoreTest.java index 04e1b8ff1b2..6a97681bb1d 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/ArtifactTestUnitStoreTest.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/ArtifactTestUnitStoreTest.java @@ -82,14 +82,16 @@ public class ArtifactTestUnitStoreTest { @Test public void testStore() throws OseeCoreException { - SkynetTransaction transaction = TransactionManager.createTransaction(testBranch, getClass().getSimpleName()); + ArtifactTestUnitStore store = new ArtifactTestUnitStore(testBranch); TestUnitCache tc = new TestUnitCache(store); CoverageItem ci = createCoverageItem(tc); ci.addTestUnitName("test1"); ci.addTestUnitName("test10"); - store.store(tc, transaction); + store.store(tc); + + SkynetTransaction transaction = TransactionManager.createTransaction(testBranch, getClass().getSimpleName()); Artifact testArtifact = ArtifactQuery.getOrCreate(ArtifactTestUnitStore.COVERAGE_GUID, null, CoreArtifactTypes.GeneralData, testBranch); String actual = testArtifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, ""); diff --git a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/MockTestUnitStore.java b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/MockTestUnitStore.java index 4e53eaaf221..84d8adf5e84 100644 --- a/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/MockTestUnitStore.java +++ b/plugins/org.eclipse.osee.coverage.test/src/org/eclipse/osee/coverage/test/store/MockTestUnitStore.java @@ -13,7 +13,6 @@ package org.eclipse.osee.coverage.test.store; import org.eclipse.osee.coverage.store.ITestUnitStore; import org.eclipse.osee.coverage.store.TestUnitCache; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; /** * @author John Misinco @@ -28,7 +27,7 @@ public class MockTestUnitStore implements ITestUnitStore { @SuppressWarnings("unused") @Override - public void store(TestUnitCache cache, SkynetTransaction transaction) throws OseeCoreException { + public void store(TestUnitCache cache) throws OseeCoreException { // do nothing } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/blam/TxCoveragePartitionsReportBlam.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/blam/TxCoveragePartitionsReportBlam.java index 33e9d13c98c..9087768ff0a 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/blam/TxCoveragePartitionsReportBlam.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/blam/TxCoveragePartitionsReportBlam.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.logging.Level; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.nebula.widgets.xviewer.Activator; diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeManager.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeManager.java index ba59a4b68e3..7a952b0cde6 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeManager.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeManager.java @@ -53,10 +53,8 @@ public class MergeManager { List<IMergeItem> mergeItems = new ArrayList<IMergeItem>(); processedImportCoverages.clear(); Collection<? extends ICoverage> children = coverageImport.getChildren(); - int count = 0; for (ICoverage importCoverage : children) { processImportCoverage(importCoverage, mergeItems, resultData); - count++; } if (mergeItems.isEmpty()) { mergeItems.add(new MessageMergeItem("Nothing to Import")); diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/ITestUnitProvider.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/ITestUnitProvider.java index c9357fd0cd7..05badac6b3a 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/ITestUnitProvider.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/ITestUnitProvider.java @@ -12,7 +12,6 @@ package org.eclipse.osee.coverage.model; import java.util.Collection; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; /** * Allow external mechnism for test units to be provided to UI @@ -33,6 +32,6 @@ public interface ITestUnitProvider { public void fromXml(CoverageItem coverageItem, String xml) throws OseeCoreException; - public void save(SkynetTransaction transaction) throws OseeCoreException; + public void save() throws OseeCoreException; } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/MessageCoverageItem.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/MessageCoverageItem.java index 64b39ddae5c..8c9ad8ba144 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/MessageCoverageItem.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/MessageCoverageItem.java @@ -12,7 +12,6 @@ package org.eclipse.osee.coverage.model; import java.util.Collection; import java.util.Collections; - import org.eclipse.osee.framework.core.data.NamedIdentity; import org.eclipse.osee.framework.core.util.Result; import org.eclipse.osee.framework.jdk.core.util.GUID; diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/SimpleTestUnitProvider.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/SimpleTestUnitProvider.java index 7b61a5d9015..92d9aeae4ec 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/SimpleTestUnitProvider.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/model/SimpleTestUnitProvider.java @@ -14,7 +14,6 @@ import java.util.Collection; import org.eclipse.osee.framework.jdk.core.type.HashCollection; import org.eclipse.osee.framework.jdk.core.util.Collections; import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; /** * Simple provider that optimizes how test units are stored by sharing test unit names. @@ -72,7 +71,7 @@ public class SimpleTestUnitProvider implements ITestUnitProvider { } @Override - public void save(SkynetTransaction transaction) { + public void save() { // do nothing cause storeage is in memory only } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ArtifactTestUnitStore.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ArtifactTestUnitStore.java index 112ea9d4673..539c01bd54f 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ArtifactTestUnitStore.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ArtifactTestUnitStore.java @@ -27,6 +27,7 @@ import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; +import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; /** * @author John Misinco @@ -57,9 +58,11 @@ public class ArtifactTestUnitStore implements ITestUnitStore { } @Override - public void store(TestUnitCache cache, SkynetTransaction transaction) throws OseeCoreException { + public void store(TestUnitCache cache) throws OseeCoreException { Artifact artifact = getCoverageTestUnitArtifact(); + SkynetTransaction transaction = TransactionManager.createTransaction(branch, "Store CoverageTestUnitArtifact"); + Set<Entry<Integer, String>> entries = cache.getAllCachedTestUnitEntries(); List<Entry<Integer, String>> entriesList = new ArrayList<Entry<Integer, String>>(entries); Collections.sort(entriesList, new Comparator<Entry<Integer, String>>() { @@ -73,6 +76,7 @@ public class ArtifactTestUnitStore implements ITestUnitStore { String storage = asStorage(entriesList); artifact.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, storage); artifact.persist(transaction); + transaction.execute(); } protected String asStorage(List<Entry<Integer, String>> entries) { diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ITestUnitStore.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ITestUnitStore.java index 6c7142ac0be..e3d3b33571c 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ITestUnitStore.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/ITestUnitStore.java @@ -11,7 +11,6 @@ package org.eclipse.osee.coverage.store; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; /** * @author John Misinco @@ -20,6 +19,6 @@ public interface ITestUnitStore { public void load(TestUnitCache cache) throws OseeCoreException; - public void store(TestUnitCache cache, SkynetTransaction transaction) throws OseeCoreException; + public void store(TestUnitCache cache) throws OseeCoreException; }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/OseeCoverageUnitStore.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/OseeCoverageUnitStore.java index 56e7a58addf..a09d0f814f7 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/OseeCoverageUnitStore.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/OseeCoverageUnitStore.java @@ -249,7 +249,9 @@ public class OseeCoverageUnitStore extends OseeCoverageStore { } coverageEvent.getCoverages().add(change); } - getTestUnitProvider().save(transaction); + + getTestUnitProvider().save(); + return Result.TrueResult; } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/TestUnitCache.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/TestUnitCache.java index 33fc7f73285..63757497039 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/TestUnitCache.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/store/TestUnitCache.java @@ -26,7 +26,6 @@ import org.eclipse.osee.framework.jdk.core.type.HashCollection; import org.eclipse.osee.framework.jdk.core.util.Collections; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; import com.google.common.collect.HashBiMap; /** @@ -42,8 +41,9 @@ public class TestUnitCache implements ITestUnitProvider { private final HashBiMap<Integer, String> idToNameCache; private final ITestUnitStore testUnitStore; - private boolean ensurePopulatedRanOnce; - private boolean cacheIsDirty; + + private volatile boolean ensurePopulatedRanOnce; + private volatile boolean cacheIsDirty; public TestUnitCache(ITestUnitStore testUnitStore) { super(); @@ -70,7 +70,7 @@ public class TestUnitCache implements ITestUnitProvider { put(key, testUnitName); } - public void put(Integer key, String testUnitName) throws OseeCoreException { + public synchronized void put(Integer key, String testUnitName) throws OseeCoreException { ensurePopulated(); if (idToNameCache.containsKey(key) && !idToNameCache.get(key).equalsIgnoreCase(testUnitName)) { throw new OseeArgumentException("TestUnit key: [%s] has already been used", key); @@ -194,10 +194,10 @@ public class TestUnitCache implements ITestUnitProvider { } @Override - public void save(SkynetTransaction transaction) throws OseeCoreException { + public synchronized void save() throws OseeCoreException { ensurePopulated(); if (cacheIsDirty) { - testUnitStore.store(this, transaction); + testUnitStore.store(this); cacheIsDirty = false; } } diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/ITraceUnitResourceLocator.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/ITraceUnitResourceLocator.java index 372ac4c23d9..14e2f526a2c 100644 --- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/ITraceUnitResourceLocator.java +++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/ITraceUnitResourceLocator.java @@ -11,7 +11,6 @@ package org.eclipse.osee.define.traceability; import java.nio.CharBuffer; - import org.eclipse.osee.define.utility.IResourceLocator; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.exception.OseeCoreException; diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/utility/IResourceHandler.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/utility/IResourceHandler.java index 52b7627baaf..7cfd7a813de 100644 --- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/utility/IResourceHandler.java +++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/utility/IResourceHandler.java @@ -12,7 +12,6 @@ package org.eclipse.osee.define.utility; import java.net.URI; import java.nio.CharBuffer; - import org.eclipse.osee.framework.core.exception.OseeCoreException; /** diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java index da4a0cc0e85..7201000b2af 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java @@ -47,8 +47,7 @@ import org.eclipse.osee.framework.skynet.core.importing.parsers.ParsersSuite; import org.eclipse.osee.framework.skynet.core.relation.CrossBranchLinkTest; import org.eclipse.osee.framework.skynet.core.relation.RelationTestSuite; import org.eclipse.osee.framework.skynet.core.revision.ConflictTest; -import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransactionTest; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManagerTest; +import org.eclipse.osee.framework.skynet.core.transaction.TransactionTestSuite; import org.eclipse.osee.framework.skynet.core.utility.CsvArtifactTest; import org.eclipse.osee.framework.skynet.core.word.UpdateBookmarkIdTest; import org.junit.AfterClass; @@ -76,8 +75,7 @@ import org.junit.runners.Suite; EventBasicGuidRelationTest.class, EventChangeTypeBasicGuidArtifactTest.class, ArtifactQueryTestDemo.class, - SkynetTransactionTest.class, - TransactionManagerTest.class, + TransactionTestSuite.class, ArtifactTestSuite.class, RelationTestSuite.class, ArtifactTypeInheritanceTest.class, diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionTest.java index 9fabe21b210..6c00c0470e0 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionTest.java @@ -92,8 +92,8 @@ public class PurgeTransactionTest { for (Artifact softArt : softArts) { softArt.persist(createTransaction); } - createId = createTransaction.getTransactionNumber(); createTransaction.execute(); + createId = createTransaction.getTransactionId(); } private void modifyArtifacts() throws Exception { @@ -103,8 +103,8 @@ public class PurgeTransactionTest { softArt.addAttribute(CoreAttributeTypes.StaticId, getClass().getSimpleName()); softArt.persist(modifyTransaction); } - modifyId = modifyTransaction.getTransactionNumber(); modifyTransaction.execute(); + modifyId = modifyTransaction.getTransactionId(); } private void purge(int transactionId, Map<String, Integer> dbCount) throws Exception { diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestDemo.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestDemo.java index b60a96eeca2..4ffbc3033de 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestDemo.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestDemo.java @@ -12,8 +12,6 @@ package org.eclipse.osee.framework.skynet.core.artifact.search; import static org.eclipse.osee.framework.core.enums.DeletionFlag.INCLUDE_DELETED; import java.util.List; - -import org.junit.Assert; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.DeletionFlag; import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; @@ -23,7 +21,7 @@ import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager; import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; -import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.junit.Assert; import org.junit.Test; /** diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestProduction.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestProduction.java index b1cde0948b2..e8723a8836e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestProduction.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQueryTestProduction.java @@ -11,7 +11,6 @@ package org.eclipse.osee.framework.skynet.core.artifact.search; import static org.junit.Assert.assertEquals; - import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/TransactionEventTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/TransactionEventTest.java index 4e77a788ff9..b37e13872a8 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/TransactionEventTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/TransactionEventTest.java @@ -89,9 +89,9 @@ public abstract class TransactionEventTest { // Make a change that we can delete newArt.setName(CHANGE_NAME); SkynetTransaction transaction = TransactionManager.createTransaction(newArt.getBranch(), "changed"); - int transIdToDelete = transaction.getTransactionNumber(); newArt.persist(transaction); transaction.execute(); + int transIdToDelete = transaction.getTransactionId(); if (!isRemoteTest()) { Assert.assertEquals(CHANGE_NAME, newArt.getName()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransactionTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransactionTest.java index 6896fc07a07..34f51101bf0 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransactionTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransactionTest.java @@ -10,9 +10,18 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.transaction; +import java.util.HashSet; +import java.util.Set; import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager; +import org.eclipse.osee.framework.skynet.core.rule.OseeHousekeepingRule; import org.eclipse.osee.support.test.util.DemoSawBuilds; +import org.junit.After; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -23,105 +32,206 @@ import org.junit.rules.TestName; */ public final class SkynetTransactionTest { - public static final String MSG = "%s.%s %d"; + @Rule + public OseeHousekeepingRule rule = new OseeHousekeepingRule(); @Rule public TestName testName = new TestName(); - @Test(expected = OseeCoreException.class) + @After + public void tearDown() { + System.gc(); + } + + @Test(expected = OseeStateException.class) public void test_overalappingTransactions() throws OseeCoreException { - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 1)); + SkynetTransaction trans1 = TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, createComment(1)); - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 2)); + SkynetTransaction trans2 = TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, createComment(2)); + + Artifact artifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + + try { + trans1.addArtifact(artifact); + trans2.addArtifact(artifact); + } finally { + artifact.purgeFromBranch(); + } } @Test - public void test_overalappingTransactionsDifferentBranches() throws OseeCoreException { + public void test_overalappingTransactionsButWithDifferentArtifacts() throws OseeCoreException { + + SkynetTransaction trans1 = TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, createComment(1)); + SkynetTransaction trans2 = TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, createComment(2)); + + Artifact artifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + Artifact artifact2 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + + boolean wasAdded = false; + try { + trans1.addArtifact(artifact1); + trans2.addArtifact(artifact2); + wasAdded = true; + } finally { + artifact1.purgeFromBranch(); + artifact2.purgeFromBranch(); + } + Assert.assertTrue(wasAdded); + } + + @Test + public void test_overalappingTransactionsDifferentBranches() throws Exception { + Object lock = new Object(); + + WorkerThread thread1 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_1, WorkerType.PRIMARY); + WorkerThread thread2 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_2, WorkerType.SECONDARY); - SkynetTransaction trans1 = - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_2, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 1)); + Artifact artifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + Artifact artifact2 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_2); - SkynetTransaction trans2 = - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 2)); + thread1.addItem(artifact1); + thread2.addItem(artifact2); - trans1.execute(); - trans2.execute(); + executeThreads(thread1, thread2); + + checkNull(thread1.getException()); + checkNull(thread2.getException()); + + artifact1.purgeFromBranch(); + artifact2.purgeFromBranch(); } @Test public void test_multiThreadedOveralappingTransactions() throws Exception { - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 1)); + Object lock = new Object(); + + WorkerThread thread1 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_1, WorkerType.PRIMARY); + WorkerThread thread2 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_1, WorkerType.SECONDARY); + + Artifact artifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + Artifact artifact2 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + + thread1.addItem(artifact1); + thread2.addItem(artifact2); - ThreadedWorker worker = new ThreadedWorker(2, DemoSawBuilds.SAW_Bld_1); - worker.execute(); + executeThreads(thread1, thread2); - worker.join(); + checkNull(thread1.getException()); + checkNull(thread2.getException()); - worker.finish(); - Assert.assertTrue(worker.caughtOseeCoreException); + artifact1.purgeFromBranch(); + artifact2.purgeFromBranch(); } @Test - public void test_multiThreadedDifferentBranches() throws Exception { - TransactionManager.createTransaction(DemoSawBuilds.SAW_Bld_1, String.format(MSG, SkynetTransactionTest.class.getSimpleName(), - testName.getMethodName(), 1)); - ThreadedWorker worker = new ThreadedWorker(2, DemoSawBuilds.SAW_Bld_2); - worker.execute(); - worker.join(); - worker.finish(); - Assert.assertFalse(worker.caughtOseeCoreException); + public void test_multiThreadedCoModificationOveralappingTransactions() throws Exception { + Object lock = new Object(); + + WorkerThread thread1 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_1, WorkerType.PRIMARY); + WorkerThread thread2 = new WorkerThread(lock, DemoSawBuilds.SAW_Bld_1, WorkerType.SECONDARY); + + Artifact artifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1); + + thread1.addItem(artifact1); + thread2.addItem(artifact1); + + executeThreads(thread1, thread2); + + checkNull(thread1.getException()); + checkNotNull(thread2.getException()); + + artifact1.purgeFromBranch(); } - private class ThreadedWorker implements Runnable { + private static void checkNotNull(Throwable ex) { + Assert.assertNotNull(ex); + Assert.assertEquals(Lib.exceptionToString(ex), OseeStateException.class, ex.getClass()); + } - private static final String TRANS_COMMENT = "%s Id: %d"; - private final Thread myThread; - private SkynetTransaction governingTransaction; - private final IOseeBranch branch; - public boolean caughtOseeCoreException; - private final int manualId; - - public ThreadedWorker(int id, IOseeBranch branchToken) { - this.manualId = id; - this.branch = branchToken; - this.caughtOseeCoreException = false; - this.myThread = new Thread(this, "Threaded Worker #" + id); - } + private static void checkNull(Throwable ex) { + Assert.assertEquals(Lib.exceptionToString(ex), (Throwable) null, ex); + } - @Override - public void run() { - try { - governingTransaction = - TransactionManager.createTransaction(branch, String.format(TRANS_COMMENT, SkynetTransactionTest.class.getSimpleName(), - manualId)); - //hold onto this transaction - } catch (OseeCoreException ex) { - caughtOseeCoreException = true; + private void executeThreads(Thread... threads) throws Exception { + boolean first = true; + + for (Thread thread : threads) { + thread.start(); + if (first) { + first = false; + synchronized (this) { + wait(500); + } } } - - public void join() throws InterruptedException { - myThread.join(); + for (Thread thread : threads) { + thread.join(); } + } - public void execute() { - myThread.start(); + private String createComment(int index) { + return String.format("%s.%s %d", getClass().getSimpleName(), testName.getMethodName(), index); + } + + private static enum WorkerType { + PRIMARY, + SECONDARY; + } + + private class WorkerThread extends Thread { + private final IOseeBranch branch; + private final Object lock; + private final Set<Artifact> data = new HashSet<Artifact>(); + private Throwable ex; + private final WorkerType workerType; + + public WorkerThread(Object lock, IOseeBranch branch, WorkerType workerType) { + this.lock = lock; + this.branch = branch; + this.workerType = workerType; } - public void finish() throws OseeCoreException { - finish(false); + public void addItem(Artifact artifact) { + data.add(artifact); } - public void finish(boolean executeTransaction) throws OseeCoreException { - if (executeTransaction && governingTransaction != null) { - governingTransaction.execute(); + @Override + public void run() { + try { + String comment = createComment(WorkerType.PRIMARY == workerType ? 1 : 2); + SkynetTransaction transaction = TransactionManager.createTransaction(branch, comment); + + try { + for (Artifact artifact : data) { + artifact.persist(transaction); + } + if (WorkerType.PRIMARY == workerType) { + synchronized (lock) { + try { + lock.wait(); + } catch (InterruptedException ex) { + // + } + } + } + } finally { + if (WorkerType.SECONDARY == workerType) { + synchronized (lock) { + lock.notifyAll(); + } + } + } + + transaction.execute(); + } catch (Throwable ex) { + this.ex = ex; } } + + public Throwable getException() { + return ex; + } } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionTestSuite.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionTestSuite.java new file mode 100644 index 00000000000..b0da1b93b49 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionTestSuite.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TxMonitorCacheTest.class, + TxMonitorImplTest.class, + TransactionManagerTest.class, + SkynetTransactionTest.class}) +/** + * @author Roberto E. Escobar + */ +public class TransactionTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCacheTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCacheTest.java new file mode 100644 index 00000000000..40642d17f02 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCacheTest.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.MonitoredTx; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.TxState; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test Case for {@link TxMonitorCache} + * + * @author Roberto E. Escobar + */ +public class TxMonitorCacheTest { + + @Test + public void testCache() { + Object key1 = new Object(); + Object key2 = new Object(); + + TxMonitorCache<Object> cache = new TxMonitorCache<Object>(); + + MonitoredTx tx1 = createTx(); + MonitoredTx tx2 = createTx(); + MonitoredTx tx3 = createTx(); + MonitoredTx tx4 = createTx(); + + cache.putTx(key1, tx1); + cache.putTx(key1, tx2); + + cache.putTx(key2, tx3); + cache.putTx(key2, tx4); + + Assert.assertTrue(cache.contains(key1)); + Assert.assertTrue(cache.contains(key2)); + Assert.assertTrue(cache.contains(key1, tx1.getUuid())); + Assert.assertTrue(cache.contains(key1, tx2.getUuid())); + + Assert.assertTrue(cache.contains(key2, tx3.getUuid())); + Assert.assertTrue(cache.contains(key2, tx4.getUuid())); + + Assert.assertFalse(cache.contains(key1, tx3.getUuid())); + + Assert.assertEquals(2, cache.getTxs(key1).size()); + Assert.assertEquals(2, cache.getTxs(key2).size()); + + Assert.assertEquals(tx1, cache.getTx(key1, tx1.getUuid())); + + String tx2Uuid = tx2.getUuid(); + Assert.assertEquals(tx2, cache.getTx(key1, tx2Uuid)); + tx2 = null; + System.gc(); + Assert.assertNull(cache.getTx(key1, tx2Uuid)); + + Assert.assertEquals(1, cache.getTxs(key1).size()); + Assert.assertEquals(2, cache.getTxs(key2).size()); + + cache.removeTx(key1, tx1.getUuid()); + Assert.assertNull(cache.getTx(key1, tx1.getUuid())); + Assert.assertEquals(0, cache.getTxs(key1).size()); + Assert.assertEquals(2, cache.getTxs(key2).size()); + + tx3 = null; + tx4 = null; + System.gc(); + Assert.assertEquals(0, cache.getTxs(key1).size()); + Assert.assertEquals(0, cache.getTxs(key2).size()); + } + + private static MonitoredTx createTx() { + return new MockMonitoredTx(GUID.create()); + } + + private static final class MockMonitoredTx implements MonitoredTx { + + private final String uuid; + + public MockMonitoredTx(String uuid) { + this.uuid = uuid; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public TxState getTxState() { + return null; + } + + @Override + public boolean containsItem(Object object) { + return false; + } + + @Override + public void rollback() { + // Do nothing + } + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImplTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImplTest.java new file mode 100644 index 00000000000..b3c3273f054 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImplTest.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import java.util.HashSet; +import java.util.Set; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.MonitoredTx; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.TxState; +import org.junit.Before; +import org.junit.Test; + +/** + * Test Case for {@link TxMonitorImpl} + * + * @author Roberto E. Escobar + */ +public class TxMonitorImplTest { + + private Object key1; + private Object key2; + + private MockMonitoredTx tx1; + private MockMonitoredTx tx2; + + private TxMonitorImpl<Object> txMonitor; + private TxMonitorCache<Object> txCache; + + @Before + public void setUp() { + key1 = new Object(); + key2 = new Object(); + + tx1 = createTx(); + tx2 = createTx(); + + txCache = new TxMonitorCache<Object>(); + txMonitor = new TxMonitorImpl<Object>(txCache); + } + + @Test(expected = OseeStateException.class) + public void testCreatedButNotInCreatedState() throws OseeCoreException { + tx1.setTxState(TxState.ENDED); + txMonitor.createTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testCreatedButWasFoundInCache() throws OseeCoreException { + txCache.putTx(key1, tx1); + txMonitor.createTx(key1, tx1); + } + + @Test + public void testCreateAddsItem() throws OseeCoreException { + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + txMonitor.createTx(key1, tx1); + Assert.assertTrue(txCache.contains(key1, tx1.getUuid())); + } + + @Test(expected = OseeStateException.class) + public void testBeginButNotInCache() throws OseeCoreException { + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + txMonitor.beginTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testBeginButInEndedState() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.ENDED); + txMonitor.beginTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testBeginButInRunningState() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.RUNNING); + txMonitor.beginTx(key1, tx1); + } + + @Test + public void testBeginCreated() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.CREATED); + txMonitor.beginTx(key1, tx1); + } + + @Test + public void testBeginModified() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.MODIFIED); + txMonitor.beginTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testEndButNotInCache() throws OseeCoreException { + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + txMonitor.endTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testEndButNotInEndedState() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.RUNNING); + txMonitor.endTx(key1, tx1); + } + + @Test + public void testEndInEndedState() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.ENDED); + Assert.assertTrue(txCache.contains(key1, tx1.getUuid())); + txMonitor.endTx(key1, tx1); + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + } + + @Test + public void testEndInEndedWithExceptionState() throws OseeCoreException { + txCache.putTx(key1, tx1); + tx1.setTxState(TxState.ENDED_WITH_EXCEPTION); + Assert.assertTrue(txCache.contains(key1, tx1.getUuid())); + txMonitor.endTx(key1, tx1); + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + } + + @Test(expected = OseeStateException.class) + public void testRollbackButNotInCache() throws OseeCoreException { + Assert.assertFalse(txCache.contains(key1, tx1.getUuid())); + txMonitor.rollbackTx(key1, tx1); + } + + @Test + public void testRollback() throws OseeCoreException { + txCache.putTx(key1, tx1); + Assert.assertFalse(tx1.wasRollbackCalled()); + txMonitor.rollbackTx(key1, tx1); + Assert.assertTrue(tx1.wasRollbackCalled()); + } + + @Test + public void testNormalPath() throws OseeCoreException { + tx1.setTxState(TxState.CREATED); + txMonitor.createTx(key1, tx1); + txMonitor.beginTx(key1, tx1); + tx1.setTxState(TxState.ENDED); + txMonitor.endTx(key1, tx1); + } + + @Test(expected = OseeStateException.class) + public void testCoModificationFail() throws OseeCoreException { + Object toModify = new Object(); + tx1.addItem(toModify); + tx2.addItem(toModify); + txCache.putTx(key1, tx1); + txCache.putTx(key1, tx2); + txMonitor.checkForComodification(key1, tx1, toModify); + } + + @Test + public void testCoModificationOk() throws OseeCoreException { + Object toModify = new Object(); + tx1.addItem(toModify); + tx2.addItem(toModify); + txCache.putTx(key1, tx1); + txCache.putTx(key2, tx2); + txMonitor.checkForComodification(key1, tx1, toModify); + } + + private static MockMonitoredTx createTx() { + return new MockMonitoredTx(GUID.create(), TxState.CREATED); + } + + private static final class MockMonitoredTx implements MonitoredTx { + + private final String uuid; + private TxState txState; + private boolean rolledBack; + private final Set<Object> data = new HashSet<Object>(); + + public MockMonitoredTx(String uuid, TxState txState) { + this.uuid = uuid; + this.txState = txState; + } + + public void addItem(Object object) { + data.add(object); + } + + public boolean wasRollbackCalled() { + return rolledBack; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setTxState(TxState txState) { + this.txState = txState; + } + + @Override + public TxState getTxState() { + return txState; + } + + @Override + public boolean containsItem(Object object) { + return data.contains(object); + } + + @Override + public void rollback() { + rolledBack = true; + } + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java index 6c726ce842c..e9caccc2b77 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java @@ -1074,7 +1074,8 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt * Removes artifact from a specific branch */ public final void deleteAndPersist() throws OseeCoreException { - SkynetTransaction transaction = TransactionManager.createTransaction(branch, "Delete artifact from a specific branch"); + SkynetTransaction transaction = + TransactionManager.createTransaction(branch, "Delete artifact from a specific branch"); deleteAndPersist(transaction); transaction.execute(); } @@ -1524,10 +1525,8 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt @Override public final int hashCode() { - int hashCode = 11; - hashCode = hashCode * 37 + getGuid().hashCode(); - hashCode = hashCode * 37 + getBranch().hashCode(); - return hashCode; + // Don't use branch so we are consistent with equals method + return super.hashCode(); } /** @@ -1548,7 +1547,7 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt } if (obj instanceof IArtifact) { IArtifact other = (IArtifact) obj; - boolean result = getArtId() == other.getArtId(); + boolean result = getGuid().equals(other.getGuid()); if (result) { if (getBranch() != null && other.getBranch() != null) { result = getBranch().equals(other.getBranch()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransaction.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransaction.java index e4de047de49..85a8e110ed4 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransaction.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/SkynetTransaction.java @@ -29,7 +29,6 @@ import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.RelationTypeSide; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.access.PermissionStatus; -import org.eclipse.osee.framework.core.operation.AbstractOperation; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.database.core.ConnectionHandler; @@ -47,6 +46,7 @@ import org.eclipse.osee.framework.skynet.core.internal.Activator; import org.eclipse.osee.framework.skynet.core.relation.RelationEventType; import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.relation.RelationTransactionData; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.TxState; import org.eclipse.osee.framework.skynet.core.types.IArtifact; /** @@ -55,31 +55,23 @@ import org.eclipse.osee.framework.skynet.core.types.IArtifact; * @author Ryan D. Brooks * @author Jeff C. Phillips */ -public final class SkynetTransaction extends AbstractOperation { - - private TransactionRecord transactionId; +public final class SkynetTransaction extends TransactionOperation<Branch> { private final CompositeKeyHashMap<Class<? extends BaseTransactionData>, Integer, BaseTransactionData> transactionDataItems = new CompositeKeyHashMap<Class<? extends BaseTransactionData>, Integer, BaseTransactionData>(); - // Used to avoid garbage collection of artifacts until the transaction has been committed; - private final Set<Artifact> artifactReferences = new HashSet<Artifact>(); + // Used to avoid garbage collection of artifacts until the transaction has been committed and determine attribute events; + private final Set<Artifact> modifiedArtifacts = new HashSet<Artifact>(); private final Set<Artifact> alreadyProcessedArtifacts = new HashSet<Artifact>(); - private final Branch branch; - private boolean madeChanges = false; - private final String comment; private User user; private AccessPolicy access; + private int transactionId = -1; - private final TransactionMonitor txMonitor; - - protected SkynetTransaction(TransactionMonitor txMonitor, Branch branch, String comment) { - super(comment, Activator.PLUGIN_ID); - this.txMonitor = txMonitor; - this.branch = branch; + protected SkynetTransaction(TxMonitor<Branch> txMonitor, Branch branch, String uuid, String comment) { + super(txMonitor, branch, uuid, comment); this.comment = comment; } @@ -183,47 +175,32 @@ public final class SkynetTransaction extends AbstractOperation { } private Collection<Artifact> getArtifactReferences() { - return artifactReferences; - } - - private TransactionRecord getTransactionRecord() throws OseeCoreException { - if (transactionId == null) { - transactionId = TransactionManager.internalCreateTransactionRecord(branch, getAuthor(), comment); - } - return transactionId; + return modifiedArtifacts; } /** * Reset state so transaction object can be re-used */ - private void reset() { - madeChanges = false; + @Override + protected void clear() { transactionDataItems.clear(); - artifactReferences.clear(); + modifiedArtifacts.clear(); alreadyProcessedArtifacts.clear(); - transactionId = null; } public Branch getBranch() { - return branch; - } - - /** - * Returns the next transaction to be used by the system<br> - * <br> - * IF transaction has not been executed, this is the transaction that will be used.<br> - * ELSE this is next transaction to be used upon execute - */ - public int getTransactionNumber() throws OseeCoreException { - return getTransactionRecord().getId(); + return getKey(); } public void addArtifact(Artifact artifact) throws OseeCoreException { - addArtifact(artifact, true); + synchronized (getTxMonitor()) { + addArtifact(artifact, true); + } } private void addArtifact(Artifact artifact, boolean force) throws OseeCoreException { if (artifact != null) { + ensureCanBeAdded(artifact); boolean wasAdded = alreadyProcessedArtifacts.add(artifact); if (wasAdded || force) { addArtifactAndAttributes(artifact); @@ -243,12 +220,12 @@ public final class SkynetTransaction extends AbstractOperation { return; } checkAccess(artifact); - madeChanges = true; + setTxState(TxState.MODIFIED); if (!artifact.isInDb() || artifact.hasDirtyArtifactType() || artifact.getModType().isDeleted() || artifact.getModType() == ModificationType.REPLACED_WITH_VERSION) { BaseTransactionData txItem = transactionDataItems.get(ArtifactTransactionData.class, artifact.getArtId()); if (txItem == null) { - artifactReferences.add(artifact); + modifiedArtifacts.add(artifact); txItem = new ArtifactTransactionData(artifact); transactionDataItems.put(ArtifactTransactionData.class, artifact.getArtId(), txItem); } else { @@ -258,7 +235,7 @@ public final class SkynetTransaction extends AbstractOperation { for (Attribute<?> attribute : artifact.internalGetAttributes()) { if (attribute.isDirty()) { - artifactReferences.add(artifact); + modifiedArtifacts.add(artifact); addAttribute(artifact, attribute); } } @@ -302,58 +279,65 @@ public final class SkynetTransaction extends AbstractOperation { } public void addRelation(Artifact artifact, RelationLink link) throws OseeCoreException { - checkAccess(artifact, link); - madeChanges = true; - link.setNotDirty(); - - ModificationType modificationType; - RelationEventType relationEventType; // needed until persist undeleted modtypes and modified == rational only change - - IOseeBranch branch = link.getBranch(); - Artifact aArtifact = getArtifact(link.getAArtifactId(), branch); - Artifact bArtifact = getArtifact(link.getBArtifactId(), branch); - if (link.isInDb()) { - if (link.isUnDeleted()) { - modificationType = ModificationType.MODIFIED; // Temporary until UNDELETED persisted to DB - relationEventType = RelationEventType.Undeleted; - } else if (link.isDeleted()) { - if (aArtifact != null && aArtifact.isDeleted() || bArtifact != null && bArtifact.isDeleted()) { - modificationType = ModificationType.ARTIFACT_DELETED; - relationEventType = RelationEventType.Deleted; + synchronized (getTxMonitor()) { + checkAccess(artifact, link); + setTxState(TxState.MODIFIED); + link.setNotDirty(); + + ModificationType modificationType; + RelationEventType relationEventType; // needed until persist undeleted modtypes and modified == rational only change + + IOseeBranch branch = link.getBranch(); + Artifact aArtifact = getArtifact(link.getAArtifactId(), branch); + Artifact bArtifact = getArtifact(link.getBArtifactId(), branch); + + if (link.isInDb()) { + if (link.isUnDeleted()) { + modificationType = ModificationType.MODIFIED; // Temporary until UNDELETED persisted to DB + relationEventType = RelationEventType.Undeleted; + } else if (link.isDeleted()) { + if (aArtifact != null && aArtifact.isDeleted() || bArtifact != null && bArtifact.isDeleted()) { + modificationType = ModificationType.ARTIFACT_DELETED; + relationEventType = RelationEventType.Deleted; + } else { + modificationType = ModificationType.DELETED; + relationEventType = RelationEventType.Deleted; + } } else { - modificationType = ModificationType.DELETED; - relationEventType = RelationEventType.Deleted; + if (link.getModificationType() == ModificationType.REPLACED_WITH_VERSION) { + modificationType = link.getModificationType(); + } else { + modificationType = ModificationType.MODIFIED; + } + relationEventType = RelationEventType.ModifiedRationale; } } else { - if (link.getModificationType() == ModificationType.REPLACED_WITH_VERSION) { - modificationType = link.getModificationType(); - } else { - modificationType = ModificationType.MODIFIED; + if (link.isDeleted()) { + return; } - relationEventType = RelationEventType.ModifiedRationale; + link.internalSetRelationId(getNewRelationId()); + modificationType = ModificationType.NEW; + relationEventType = RelationEventType.Added; } - } else { - if (link.isDeleted()) { - return; - } - link.internalSetRelationId(getNewRelationId()); - modificationType = ModificationType.NEW; - relationEventType = RelationEventType.Added; - } - /** - * Always want to persist artifacts on other side of dirty relation. This is necessary for ordering attribute to - * be persisted and desired for other cases. - */ - addArtifact(aArtifact, false); - addArtifact(bArtifact, false); + /** + * Always want to persist artifacts on other side of dirty relation. This is necessary for ordering attribute + * to be persisted and desired for other cases. + */ + addArtifact(aArtifact, false); + addArtifact(bArtifact, false); - BaseTransactionData txItem = transactionDataItems.get(RelationTransactionData.class, link.getId()); - if (txItem == null) { - txItem = new RelationTransactionData(link, modificationType, relationEventType); - transactionDataItems.put(RelationTransactionData.class, link.getId(), txItem); - } else { - updateTxItem(txItem, modificationType); + BaseTransactionData txItem = transactionDataItems.get(RelationTransactionData.class, link.getId()); + if (txItem == null) { + txItem = new RelationTransactionData(link, modificationType, relationEventType); + transactionDataItems.put(RelationTransactionData.class, link.getId(), txItem); + + modifiedArtifacts.add(aArtifact); + modifiedArtifacts.add(bArtifact); + + } else { + updateTxItem(txItem, modificationType); + } } } @@ -365,26 +349,34 @@ public final class SkynetTransaction extends AbstractOperation { } } + private IOperation createStorageOp() throws OseeCoreException { + TransactionRecord transaction = + TransactionManager.internalCreateTransactionRecord(getBranch(), getAuthor(), comment); + transactionId = transaction.getId(); + return new StoreSkynetTransactionOperation(getName(), getBranch(), transaction, getTransactionData(), + getArtifactReferences()); + } + + public int getTransactionId() { + return transactionId; + } + @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - int smallWork = calculateWork(0.10); - try { - txMonitor.reportTxStart(SkynetTransaction.this, getBranch()); - monitor.worked(smallWork); - if (madeChanges) { - IOperation subOp = createStorageOp(); - doSubWork(subOp, monitor, 0.80); - } - } finally { - reset(); - txMonitor.reportTxEnd(SkynetTransaction.this, getBranch()); - monitor.worked(smallWork); + public boolean containsItem(Object object) { + synchronized (getTxMonitor()) { + return modifiedArtifacts.contains(object); } } - private IOperation createStorageOp() throws OseeCoreException { - return new StoreSkynetTransactionOperation(getName(), getBranch(), getTransactionRecord(), getTransactionData(), - getArtifactReferences()); + @Override + protected void txWork(IProgressMonitor monitor) throws Exception { + IOperation subOp = createStorageOp(); + doSubWork(subOp, monitor, 1.00); + } + + @Override + public String toString() { + return String.format("uuid:[%s] branch[%s] comment[%s]", getUuid(), getBranch(), comment); } //TODO this method needs to be removed diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java index 71c3d11464f..a02417679e7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java @@ -32,6 +32,7 @@ import org.eclipse.osee.framework.database.core.ConnectionHandler; import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.core.OseeConnection; import org.eclipse.osee.framework.database.core.OseeSql; +import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime; import org.eclipse.osee.framework.skynet.core.User; import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; @@ -66,13 +67,13 @@ public final class TransactionManager { private static final HashMap<Integer, List<TransactionRecord>> commitArtifactIdMap = new HashMap<Integer, List<TransactionRecord>>(); - private static TransactionMonitor txMonitor = new TransactionMonitor(); + private static final TxMonitorImpl<Branch> txMonitor = new TxMonitorImpl<Branch>(new TxMonitorCache<Branch>()); public static SkynetTransaction createTransaction(IOseeBranch branch, String comment) throws OseeCoreException { Branch actualBranch = BranchManager.getBranch(branch); - SkynetTransaction transaction = new SkynetTransaction(txMonitor, actualBranch, comment); - txMonitor.reportTxCreation(transaction, branch, comment); - return transaction; + SkynetTransaction tx = new SkynetTransaction(txMonitor, actualBranch, GUID.create(), comment); + txMonitor.createTx(actualBranch, tx); + return tx; } public static List<TransactionRecord> getTransaction(String comment) throws OseeCoreException { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionMonitor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionMonitor.java deleted file mode 100644 index fbbb34a228f..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionMonitor.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.skynet.core.transaction; - -import java.util.Map; -import java.util.WeakHashMap; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.OseeExceptions; -import org.eclipse.osee.framework.core.exception.OseeStateException; - -/** - * @author Roberto E. Escobar - */ -public final class TransactionMonitor { - - private enum TxState { - CREATED, - RUNNING, - ENDED; - } - - private final Map<Object, TxOperation> txMap; - - public TransactionMonitor() { - this.txMap = new WeakHashMap<Object, TxOperation>(); - } - - public synchronized void reportTxCreation(final Object transaction, Object key, String comment) throws OseeCoreException { - TxOperation op = txMap.get(key); - if (op == null) { - txMap.put(key, new TxOperation(transaction)); - } else { - txMap.put(key, null); - throw new OseeCoreException("Branch: [%s]: New transaction [%s] created over Last transaction [%s]", key, - comment, op.getTransaction().toString()); - } - } - - public synchronized void reportTxStart(final Object transaction, Object key) throws OseeCoreException { - TxOperation op = txMap.get(key); - if (op == null) { - throw new OseeStateException("reportTxStart called for key: [%s] but reportTxCreation had not been called.", - key); - } else if (op.getState() != TxState.CREATED) { - OseeExceptions.wrapAndThrow(op.getError()); - } - - if (op.getTransaction().equals(transaction)) { - op.setState(TxState.RUNNING); - } else { - throw new OseeStateException("reportTxStart called for key [%s] but was called for incorrect transaction", key); - } - } - - public synchronized void reportTxEnd(final Object transaction, Object key) throws OseeCoreException { - TxOperation op = txMap.get(key); - if (op == null) { - throw new OseeStateException( - "reportTxEnd called for key: [%s] but reportTxCreation had not been called. Comment [%s]", key, - transaction.toString()); - } else if (op.getState() != TxState.RUNNING) { - // This is a valid case -- can add a log to detect when a reportTxEnd is called before a transaction has a chance to run - } - - if (op.getTransaction().equals(transaction)) { - txMap.put(key, null); - } else { - OseeExceptions.wrapAndThrow(op.getError()); - } - } - - private static final class TxOperation { - private final Object tx; - private final Throwable throwable; - private TxState txState; - - public TxOperation(Object tx) { - this.tx = tx; - this.txState = TxState.CREATED; - // Not null for stack trace purposes; - this.throwable = new Exception(); - } - - public Object getTransaction() { - return tx; - } - - public TxState getState() { - return txState; - } - - public void setState(TxState txState) { - this.txState = txState; - } - - public Throwable getError() { - return throwable; - } - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionOperation.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionOperation.java new file mode 100644 index 00000000000..b3c9d3d1dc1 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionOperation.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.skynet.core.internal.Activator; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.MonitoredTx; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.TxState; + +/** + * @author Roberto E. Escobar + */ +public abstract class TransactionOperation<K> extends AbstractOperation implements MonitoredTx { + + private final TxMonitor<K> txMonitor; + private final K key; + private final String uuid; + private volatile TxState state; + + protected TransactionOperation(TxMonitor<K> txMonitor, K key, String uuid, String description) { + super(description, Activator.PLUGIN_ID); + this.txMonitor = txMonitor; + this.key = key; + this.uuid = uuid; + setTxState(TxState.CREATED); + } + + protected abstract void clear(); + + protected abstract void txWork(IProgressMonitor monitor) throws Exception; + + protected TxMonitor<K> getTxMonitor() { + return txMonitor; + } + + @Override + public String getUuid() { + return uuid; + } + + protected K getKey() { + return key; + } + + protected void setTxState(TxState state) { + this.state = state; + } + + @Override + public TxState getTxState() { + return state; + } + + protected void ensureCanBeAdded(Object object) throws OseeCoreException { + txMonitor.checkForComodification(getKey(), this, object); + } + + @Override + public abstract boolean containsItem(Object object); + + @SuppressWarnings("unused") + @Override + public void rollback() throws OseeCoreException { + // Do Nothing + } + + @Override + protected final void doWork(IProgressMonitor monitor) throws Exception { + synchronized (txMonitor) { + try { + txMonitor.beginTx(getKey(), this); + if (getTxState() == TxState.MODIFIED) { + setTxState(TxState.RUNNING); + txWork(SubMonitor.convert(monitor)); + } + setTxState(TxState.ENDED); + } catch (Exception ex) { + setTxState(TxState.ENDED_WITH_EXCEPTION); + txMonitor.rollbackTx(getKey(), this); + throw ex; + } finally { + try { + txMonitor.endTx(getKey(), this); + } finally { + clear(); + } + } + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MonitoredTx other = (MonitoredTx) obj; + if (uuid == null) { + if (other.getUuid() != null) { + return false; + } + } else if (!uuid.equals(other.getUuid())) { + return false; + } + return true; + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitor.java new file mode 100644 index 00000000000..dd1cc226ec5 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitor.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.MonitoredTx; + +/** + * @author Roberto E. Escobar + */ +public interface TxMonitor<K> { + + void checkForComodification(K key, MonitoredTx tx, Object object) throws OseeCoreException; + + void createTx(K key, MonitoredTx tx) throws OseeCoreException; + + void beginTx(K key, MonitoredTx tx) throws OseeCoreException; + + void endTx(K key, MonitoredTx tx) throws OseeCoreException; + + void rollbackTx(K key, MonitoredTx tx) throws OseeCoreException; + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCache.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCache.java new file mode 100644 index 00000000000..a8fad426f8b --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorCache.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.eclipse.osee.framework.skynet.core.transaction.TxMonitorImpl.MonitoredTx; + +/** + * @author Roberto E. Escobar + */ +public final class TxMonitorCache<K> { + + private final Map<K, Map<String, WeakReference<MonitoredTx>>> txMap = + new ConcurrentHashMap<K, Map<String, WeakReference<MonitoredTx>>>(); + + public boolean contains(K key) { + return txMap.containsKey(key); + } + + public boolean contains(K key, String uuid) { + return getTx(key, uuid) != null; + } + + public void putTx(K key, MonitoredTx tx) { + Map<String, WeakReference<MonitoredTx>> data = txMap.get(key); + if (data == null) { + data = new ConcurrentHashMap<String, WeakReference<MonitoredTx>>(); + txMap.put(key, data); + } + data.put(tx.getUuid(), new WeakReference<MonitoredTx>(tx)); + manageReferences(); + } + + public void removeTx(K key, String uuid) { + Map<String, WeakReference<MonitoredTx>> data = txMap.get(key); + if (data != null) { + data.remove(uuid); + } + manageReferences(); + } + + private void manageReferences() { + Set<K> toRemove = new HashSet<K>(); + for (Entry<K, Map<String, WeakReference<MonitoredTx>>> entry : txMap.entrySet()) { + Map<?, WeakReference<MonitoredTx>> data = entry.getValue(); + manageReferences(data); + if (data.isEmpty()) { + toRemove.add(entry.getKey()); + } + } + for (Object item : toRemove) { + txMap.remove(item); + } + } + + private void manageReferences(Map<?, WeakReference<MonitoredTx>> data) { + Set<Object> toRemove = new HashSet<Object>(); + for (Entry<?, WeakReference<MonitoredTx>> entry : data.entrySet()) { + WeakReference<?> reference = entry.getValue(); + if (reference == null || reference.get() == null) { + toRemove.add(entry.getKey()); + } + } + for (Object item : toRemove) { + data.remove(item); + } + } + + public MonitoredTx getTx(K key, String uuid) { + MonitoredTx toReturn = null; + Map<String, WeakReference<MonitoredTx>> data = txMap.get(key); + if (data != null) { + WeakReference<MonitoredTx> reference = data.get(uuid); + if (reference != null) { + toReturn = reference.get(); + } + if (toReturn == null) { + data.remove(uuid); + } + if (data.isEmpty()) { + txMap.remove(key); + } + } + return toReturn; + } + + public List<MonitoredTx> getTxs(K key) { + List<MonitoredTx> txs = new ArrayList<MonitoredTx>(); + Map<String, WeakReference<MonitoredTx>> data = txMap.get(key); + if (data != null) { + Set<String> toRemove = new HashSet<String>(); + for (Entry<String, WeakReference<MonitoredTx>> entry : data.entrySet()) { + WeakReference<MonitoredTx> reference = entry.getValue(); + if (reference != null) { + MonitoredTx tx = reference.get(); + if (tx != null) { + txs.add(tx); + } else { + toRemove.add(entry.getKey()); + } + } else { + toRemove.add(entry.getKey()); + } + } + for (Object item : toRemove) { + data.remove(item); + } + if (data.isEmpty()) { + txMap.remove(key); + } + } + return txs; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImpl.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImpl.java new file mode 100644 index 00000000000..0d0849be5a6 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TxMonitorImpl.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2011 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeStateException; + +/** + * Cases: + * <ul> + * <li></li> + * </ul> + * + * @author Roberto E. Escobar + */ +public final class TxMonitorImpl<K> implements TxMonitor<K> { + + public static enum TxState { + CREATED, + MODIFIED, + RUNNING, + ENDED, + ENDED_WITH_EXCEPTION; + } + + public static interface MonitoredTx { + + String getUuid(); + + TxState getTxState(); + + boolean containsItem(Object object); + + void rollback() throws OseeCoreException; + } + + private final TxMonitorCache<K> cache; + + protected TxMonitorImpl(TxMonitorCache<K> cache) { + this.cache = cache; + } + + @Override + public void checkForComodification(K key, MonitoredTx tx, Object object) throws OseeCoreException { + for (MonitoredTx otherTx : cache.getTxs(key)) { + if (!otherTx.equals(tx)) { + if (otherTx.containsItem(object)) { + throw new OseeStateException("Co-modification error for object [%s] -\ntx1:[%s]\ntx2:[%s]", object, tx, + otherTx); + } + } + } + } + + @Override + public void createTx(K key, MonitoredTx tx) throws OseeCoreException { + if (cache.contains(key, tx.getUuid())) { + throw new OseeStateException("key:[%s] tx:[%s] - transaction was already in the cache", key, tx); + } + if (tx.getTxState() != TxState.CREATED) { + throw new OseeStateException("key:[%s] tx:[%s] state:[%s] - was not in CREATED state ", key, tx, + tx.getTxState()); + } + cache.putTx(key, tx); + } + + @Override + public void beginTx(K key, MonitoredTx tx) throws OseeCoreException { + checkIsInCache(key, tx); + + TxState state = tx.getTxState(); + if (state != TxState.CREATED && state != TxState.MODIFIED) { + throw new OseeStateException("key:[%s] tx:[%s] state:[%s] - was not in CREATED or MODIFIED_STATE state", key, + tx, state); + } + } + + @Override + public void endTx(K key, MonitoredTx tx) throws OseeCoreException { + checkIsInCache(key, tx); + + TxState state = tx.getTxState(); + if (state != TxState.ENDED && state != TxState.ENDED_WITH_EXCEPTION) { + throw new OseeStateException("key:[%s] tx:[%s] state:[%s] - was not in ENDED or ENDED_WITH_EXCEPTION state", + key, tx, state); + } + cache.removeTx(key, tx.getUuid()); + } + + @Override + public void rollbackTx(K key, MonitoredTx tx) throws OseeCoreException { + checkIsInCache(key, tx); + tx.rollback(); + } + + private void checkIsInCache(K key, MonitoredTx tx) throws OseeCoreException { + if (!cache.contains(key, tx.getUuid())) { + throw new OseeStateException("key:[%s] tx:[%s] - has not been added to monitor", key, tx); + } + } + +} diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java index ed65a9be0ef..fafa056b216 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java @@ -17,8 +17,8 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.logging.OseeLevel; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.ui.skynet.internal.ArtifactPromptService; import org.eclipse.osee.framework.ui.skynet.internal.Activator; +import org.eclipse.osee.framework.ui.skynet.internal.ArtifactPromptService; /** * @author Jeff C. Phillips diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteUnneededUnspecifiedAttributes.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteUnneededUnspecifiedAttributes.java index bc91d0d2344..98a202d418b 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteUnneededUnspecifiedAttributes.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteUnneededUnspecifiedAttributes.java @@ -41,7 +41,8 @@ public class DeleteUnneededUnspecifiedAttributes extends AbstractBlam { AttributeType attributeType = variableMap.getAttributeType("Attribute Type"); List<Artifact> artifacts = ArtifactQuery.getArtifactListFromAttribute(attributeType, EnumeratedAttribute.UNSPECIFIED_VALUE, branch); - SkynetTransaction transaction = TransactionManager.createTransaction(branch, "BLAM: Delete unneeded unspecified attributes"); + SkynetTransaction transaction = + TransactionManager.createTransaction(branch, "BLAM: Delete unneeded unspecified attributes"); for (Artifact artifact : artifacts) { Collection<Attribute<String>> attributes = artifact.getAttributes(attributeType); |