Skip to content

Commit 67d7eca

Browse files
author
jodzga
committed
Relationship can be added multiple times. This can occur e.g. when a
task is scheduled by a parent and in some other way. Relationship POTENTIAL_PARENT_OF might be added twice: first when task is being run by parent but it is already running and second time when parent is resolved and thus cancelling this task.
1 parent 11eb290 commit 67d7eca

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

src/com/linkedin/parseq/trace/TraceBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public synchronized void addRelationship(final Relationship relationship, final
6767
addShallowTrace(from);
6868
addShallowTrace(to);
6969
final TraceRelationship rel = new TraceRelationship(from.getId(), to.getId(), relationship);
70-
if (!_relationships.add(rel)) {
71-
throw new IllegalArgumentException("Relationship already exists: " + rel);
72-
}
70+
_relationships.add(rel);
7371
increaseRefCount(from.getId());
7472
increaseRefCount(to.getId());
7573
}

test/com/linkedin/parseq/trace/TestTraceBuilder.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static org.testng.AssertJUnit.assertEquals;
2020
import static org.testng.AssertJUnit.assertTrue;
21-
import static org.testng.AssertJUnit.fail;
2221

2322
import org.testng.annotations.Test;
2423

@@ -59,14 +58,11 @@ public void testAddRelationshipTwice()
5958
.setResultType(ResultType.UNFINISHED);
6059
final TraceBuilder builder = new TraceBuilder(1024);
6160
builder.addRelationship(Relationship.SUCCESSOR_OF, trace1, trace2);
62-
try
63-
{
64-
builder.addRelationship(Relationship.SUCCESSOR_OF, trace1, trace2);
65-
fail("Should have thrown IllegalArgumentException");
66-
}
67-
catch (IllegalArgumentException e)
68-
{
69-
// Expected case
70-
}
61+
builder.addRelationship(Relationship.SUCCESSOR_OF, trace1, trace2);
62+
Trace trace = builder.build();
63+
assertEquals(trace1.build(), trace.getTraceMap().get(trace1.getId()));
64+
assertEquals(trace2.build(), trace.getTraceMap().get(trace2.getId()));
65+
assertEquals(1, trace.getRelationships().size());
66+
assertTrue(trace.getRelationships().contains(new TraceRelationship(trace1.getId(), trace2.getId(), Relationship.SUCCESSOR_OF)));
7167
}
7268
}

0 commit comments

Comments
 (0)