| author | john.r.misinco | 2011-04-29 19:20:43 (EDT) |
|---|---|---|
| committer | Ryan D. Brooks | 2011-04-29 19:20:43 (EDT) |
| commit | 799bedaaba7823d06d9f673437f0f713d613f0d3 (patch) (side-by-side diff) | |
| tree | 99ba156cab6edb743ee30d25a78b3a34cc02005d | |
| parent | 36ab7a56efcb461e42cb46d7d9f5007f6af31ca5 (diff) | |
| download | org.eclipse.osee-799bedaaba7823d06d9f673437f0f713d613f0d3.zip org.eclipse.osee-799bedaaba7823d06d9f673437f0f713d613f0d3.tar.gz org.eclipse.osee-799bedaaba7823d06d9f673437f0f713d613f0d3.tar.bz2 | |
bug: Fix RelationCache.deCache not removing relations from both sides
2 files changed, 58 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/relation/RelationCacheTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/relation/RelationCacheTest.java index bd8aa35..1e5c1dd 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/relation/RelationCacheTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/relation/RelationCacheTest.java @@ -13,7 +13,10 @@ package org.eclipse.osee.framework.skynet.core.test.relation; import java.util.ArrayList; import java.util.List; import junit.framework.Assert; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.DeletionFlag; +import org.eclipse.osee.framework.core.enums.ModificationType; +import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.test.mocks.MockDataFactory; @@ -23,6 +26,7 @@ import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.skynet.core.relation.RelationCache; import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.test.mocks.DataFactory; +import org.eclipse.osee.framework.skynet.core.test.mocks.MockLinker; import org.eclipse.osee.framework.skynet.core.types.IArtifact; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -330,6 +334,35 @@ public class RelationCacheTest { Assert.assertEquals(link23, actual); } + @Test + public void testDeCache() throws OseeCoreException { + RelationCache relCache = new RelationCache(); + Branch testBranch = MockDataFactory.createBranch(777); + testBranch.setId(777); + + IArtifact artifactA = createArtifact(54, testBranch); + IArtifact artifactB = createArtifact(55, testBranch); + + RelationType type = + new RelationType(GUID.create(), "type name", artifactA.getName(), artifactB.getName(), + CoreArtifactTypes.Artifact, CoreArtifactTypes.Artifact, RelationTypeMultiplicity.MANY_TO_MANY, ""); + RelationLink link = + new RelationLink(new MockLinker("linker"), artifactA.getArtId(), artifactB.getArtId(), testBranch, type, 77, + 88, "", ModificationType.MODIFIED); + relCache.cache(artifactA, link); + relCache.cache(artifactB, link); + + List<RelationLink> artARels = relCache.getAll(artifactA); + Assert.assertEquals(1, artARels.size()); + + relCache.deCache(artifactA); + artARels = relCache.getAll(artifactA); + Assert.assertEquals(0, artARels.size()); + + List<RelationLink> artBRels = relCache.getAll(artifactB); + Assert.assertEquals(0, artBRels.size()); + } + private static void checkAssumptions() { Assert.assertTrue(!artfact1.equals(artfact2)); Assert.assertTrue(artfact1.getBranch().getId() != artfact2.getBranch().getId()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java index 4b09081..9f71a49 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java @@ -57,7 +57,31 @@ public class RelationCache { } public void deCache(IArtifact artifact) { - relationsByType.removeValues(getKey(artifact)); + ArtifactKey key = getKey(artifact); + Collection<List<RelationLink>> removeValues = relationsByType.removeValues(key); + + if (removeValues != null) { + for (List<RelationLink> relations : removeValues) { + for (RelationLink relation : relations) { + removeSingleRelation(artifact, relation); + } + } + } + } + + private void removeSingleRelation(IArtifact otherArtifact, RelationLink relation) { + int artifactId; + if (otherArtifact.getArtId() == relation.getBArtifactId()) { + artifactId = relation.getAArtifactId(); + } else { + artifactId = relation.getBArtifactId(); + } + + ArtifactKey key = getKey(artifactId, relation.getBranch().getId()); + List<RelationLink> relations = relationsByType.get(key, relation.getRelationType()); + if (relations != null) { + relations.remove(relation); + } } public void cache(IArtifact artifact, RelationLink newRelation) { |

