Skip to content

Commit

Permalink
Refactor and fix puppy for metaclient (apache#2870)
Browse files Browse the repository at this point in the history
Refactor and fix puppy for metaclient
  • Loading branch information
xyuanlu authored and Harrison Tin committed Aug 23, 2024
1 parent 4db77ac commit 3ebb575
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
public class CreatePuppy extends AbstractPuppy {

private final Random _random;
private final String _parentPath = "/test";

public CreatePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
public CreatePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
super(metaclient, puppySpec, parentPath);
_random = new Random();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
public class DeletePuppy extends AbstractPuppy {

private final Random _random;
private final String _parentPath = "/test";
private final String _parentPath;

public DeletePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
public DeletePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
super(metaclient, puppySpec, parentPath);
_random = new Random();
_parentPath = parentPath;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class GetPuppy extends AbstractPuppy {
private final Random _random;
private final String _parentPath = "/test";

public GetPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
public GetPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
super(metaclient, puppySpec, parentPath);
_random = new Random();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class SetPuppy extends AbstractPuppy {
private final Random _random;
private final String _parentPath = "/test";

public SetPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
public SetPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
super(metaclient, puppySpec, parentPath);
_random = new Random();
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
public class UpdatePuppy extends AbstractPuppy {

private final Random _random;
private final String _parentPath = "/test";

public UpdatePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
public UpdatePuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
super(metaclient, puppySpec, parentPath);
_random = new Random();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,12 @@ public static void simulateZkStateClosedAndReconnect(ZkMetaClient client) throws
zkClient.process(event);
}

/**
* return the name of the calling test method
*/
public static String getTestMethodName() {
StackTraceElement[] calls = Thread.currentThread().getStackTrace();
return calls[2].getMethodName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public abstract class AbstractPuppy implements Runnable {
protected PuppySpec _puppySpec;
public final HashMap<String, Integer> _eventChangeCounterMap;
public int _unhandledErrorCounter;
protected final String _parentPath ;

public AbstractPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
public AbstractPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec, String parentPath) {
_metaclient = metaclient;
_puppySpec = puppySpec;
_eventChangeCounterMap = new HashMap<>();
_parentPath = parentPath;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ public class LeaderElectionPuppy extends AbstractPuppy {
private final Random _random;
LeaderElectionClient _leaderElectionClient;

public LeaderElectionPuppy(MetaClientInterface<String> metaclient, PuppySpec puppySpec) {
super(metaclient, puppySpec);
_random = new Random();
}

public LeaderElectionPuppy(LeaderElectionClient leaderElectionClient, PuppySpec puppySpec, String leaderGroup,
String participant) {
super(leaderElectionClient.getMetaClient(), puppySpec);
super(leaderElectionClient.getMetaClient(), puppySpec, leaderGroup);
_leaderElectionClient = leaderElectionClient;
_leaderGroup = leaderGroup;
_random = new Random();
Expand Down

0 comments on commit 3ebb575

Please sign in to comment.