Skip to content

Commit

Permalink
Lattice Puppy Stress Test Race Condition Fix and Code Cleanup (#2579)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: mapeng <[email protected]>
  • Loading branch information
Marcosrico and mapeng authored Aug 2, 2023
1 parent 0d4e2f5 commit a9c8332
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


public class MetaClientTestUtil {
public static final long WAIT_DURATION = TimeUnit.MINUTES.toMicros(1);
public static final long WAIT_DURATION = TimeUnit.MINUTES.toMillis(1);
public interface Verifier {
boolean verify()
throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ protected void bark() {

@Override
protected void cleanup() {
// Implement the recovery logic by deleting the created documents
_metaclient.recursiveDelete(_parentPath);
// Cleanup logic in test case
}

private boolean shouldIntroduceError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void bark() {

@Override
protected void cleanup() {
_metaclient.recursiveDelete(_parentPath);
// Do nothing
}

private boolean shouldIntroduceError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected void bark() {

@Override
protected void cleanup() {
_metaclient.recursiveDelete(_parentPath);
}

private boolean shouldIntroduceError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected void bark() {

@Override
protected void cleanup() {
_metaclient.recursiveDelete(_parentPath);
}

private boolean shouldIntroduceError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void setUp() {
public void testCreatePuppy() {
_zkMetaClient.create(zkParentKey, "test");

PuppySpec puppySpec = new org.apache.helix.metaclient.puppy.PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5);
PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5);
CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec);
CreatePuppy createPuppy2 = new CreatePuppy(_zkMetaClient, puppySpec);
CreatePuppy createPuppy3 = new CreatePuppy(_zkMetaClient, puppySpec);
Expand Down Expand Up @@ -189,7 +189,7 @@ public void testBasicParentListenerPuppy() {
AtomicInteger globalChildChangeCounter = new AtomicInteger();
ChildChangeListener childChangeListener = (changedPath, changeType) -> {
globalChildChangeCounter.addAndGet(1);
System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + globalChildChangeCounter.get());
System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + ". Number of total changes: " + globalChildChangeCounter.get());
};

_zkMetaClient.subscribeChildChanges(zkParentKey, childChangeListener, false);
Expand Down Expand Up @@ -219,8 +219,6 @@ public void testComplexParentListenerPuppy() {
globalChildChangeCounter.addAndGet(1);
System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + globalChildChangeCounter.get());
};


_zkMetaClient.subscribeChildChanges(zkParentKey, childChangeListener, false);

PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected void bark() throws Exception {

@Override
protected void cleanup() {
_metaclient.recursiveDelete(_parentPath);
}

private boolean shouldIntroduceError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,23 @@ public AbstractPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec
@Override
public void run() {
try {
while (true) {
while (!Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(getPuppySpec().getExecDelay().getNextDelay());
bark();
} catch (InterruptedException e) {
break;
} catch (Exception e) {
incrementUnhandledErrorCounter();
e.printStackTrace();
}

if (getPuppySpec().getMode() == PuppyMode.ONE_OFF) {
cleanup();
break;
} else {
try {
Thread.sleep(getPuppySpec().getExecDelay().getNextDelay());
} catch (InterruptedException e) {
cleanup();
break;
// Handle interruption if necessary
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
cleanup();
}
}

public PuppySpec getPuppySpec() {
Expand Down

0 comments on commit a9c8332

Please sign in to comment.