-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
401 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...uration/examples/db/redis/RedisTransformerTimeoutExceptionsAnalysisConfigurationFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cloud.filibuster.junit.configuration.examples.db.redis; | ||
|
||
import cloud.filibuster.junit.configuration.FilibusterAnalysisConfiguration; | ||
import cloud.filibuster.junit.configuration.FilibusterAnalysisConfigurationFile; | ||
import cloud.filibuster.junit.configuration.FilibusterCustomAnalysisConfigurationFile; | ||
import cloud.filibuster.junit.server.core.transformers.RedisTimeoutExceptionTransformer; | ||
|
||
public class RedisTransformerTimeoutExceptionsAnalysisConfigurationFile implements FilibusterAnalysisConfigurationFile { | ||
private static final FilibusterCustomAnalysisConfigurationFile filibusterCustomAnalysisConfigurationFile; | ||
|
||
static { | ||
FilibusterCustomAnalysisConfigurationFile.Builder filibusterCustomAnalysisConfigurationFileBuilder = new FilibusterCustomAnalysisConfigurationFile.Builder(); | ||
|
||
FilibusterAnalysisConfiguration.Builder filibusterAnalysisConfigurationBuilderRedisExceptions = new FilibusterAnalysisConfiguration.Builder() | ||
.name("java.lettuce.core.RedisCommandTimeoutException") | ||
.pattern("io.lettuce.core.api.sync.RedisStringCommands/(get|set)\\b"); | ||
|
||
filibusterAnalysisConfigurationBuilderRedisExceptions.transformer(RedisTimeoutExceptionTransformer.class); | ||
|
||
filibusterCustomAnalysisConfigurationFileBuilder.analysisConfiguration(filibusterAnalysisConfigurationBuilderRedisExceptions.build()); | ||
|
||
filibusterCustomAnalysisConfigurationFile = filibusterCustomAnalysisConfigurationFileBuilder.build(); | ||
} | ||
|
||
@Override | ||
public FilibusterCustomAnalysisConfigurationFile toFilibusterCustomAnalysisConfigurationFile() { | ||
return filibusterCustomAnalysisConfigurationFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/cloud/filibuster/junit/server/core/transformers/DBException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cloud.filibuster.junit.server.core.transformers; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
|
||
import java.util.Map; | ||
|
||
public class DBException { | ||
|
||
private final String name; | ||
private final Map<String, String> metadata; | ||
|
||
public DBException(String name, Map<String, String> metadata) { | ||
this.name = name; | ||
this.metadata = metadata; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Map<String, String> getMetadata() { | ||
return metadata; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DBException{" + | ||
"name='" + name + '\'' + | ||
", metadata=" + metadata + | ||
'}'; | ||
} | ||
|
||
public static class Builder { | ||
private String name; | ||
private Map<String, String> metadata; | ||
|
||
@CanIgnoreReturnValue | ||
public Builder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public Builder metadata(Map<String, String> metadata) { | ||
this.metadata = metadata; | ||
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public DBException build() { | ||
return new DBException(name, metadata); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...ava/cloud/filibuster/junit/server/core/transformers/RedisTimeoutExceptionTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cloud.filibuster.junit.server.core.transformers; | ||
|
||
import cloud.filibuster.exceptions.transformer.TransformerNullResultException; | ||
import cloud.filibuster.exceptions.transformer.TransformerRuntimeException; | ||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class RedisTimeoutExceptionTransformer implements Transformer<Object, Integer> { | ||
private boolean hasNext = true; | ||
private Object result; | ||
private Accumulator<Object, Integer> accumulator; | ||
private static final ArrayList<DBException> dbExceptions = new ArrayList<>(); | ||
|
||
static { | ||
DBException.Builder commandTimeoutBuilder = new DBException.Builder(); | ||
commandTimeoutBuilder.name("io.lettuce.core.RedisCommandTimeoutException"); | ||
|
||
Map<String, String> exceptionMap = new HashMap<>(); | ||
exceptionMap.put("cause", "Command timed out after 100 millisecond(s)"); | ||
exceptionMap.put("code", ""); | ||
commandTimeoutBuilder.metadata(exceptionMap); | ||
|
||
DBException commandTimeoutException = commandTimeoutBuilder.build(); | ||
dbExceptions.add(commandTimeoutException); | ||
} | ||
|
||
@Override | ||
@CanIgnoreReturnValue | ||
public RedisTimeoutExceptionTransformer transform(Object payload, Accumulator<Object, Integer> accumulator) { | ||
|
||
// Get exception corresponding to idx in context | ||
this.result = dbExceptions.get(accumulator.getContext()); | ||
this.accumulator = accumulator; | ||
|
||
// Increment context | ||
if (accumulator.getContext() < dbExceptions.size() - 1) { | ||
accumulator.setContext(accumulator.getContext() + 1); | ||
} else { | ||
this.hasNext = false; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return hasNext; | ||
} | ||
|
||
@Override | ||
public Type getPayloadType() { | ||
return Object.class; | ||
} | ||
|
||
@Override | ||
public Object getResult() { | ||
if (this.result == null) { | ||
throw new TransformerNullResultException("Result is null. getResult() was probably called before transform()!"); | ||
} | ||
return this.result; | ||
} | ||
|
||
@Override | ||
public Type getAccumulatorType() { | ||
return TypeToken.getParameterized( | ||
Accumulator.class, | ||
Object.class, | ||
Integer.class).getType(); | ||
} | ||
|
||
@Override | ||
public Accumulator<Object, Integer> getInitialAccumulator(Object referenceValue) { | ||
if (dbExceptions.size() == 0) { | ||
throw new TransformerRuntimeException("No DBExceptions were added to the DBExceptionTransformer!"); | ||
} | ||
|
||
this.result = referenceValue; | ||
|
||
Accumulator<Object, Integer> accumulator = new Accumulator<>(); | ||
accumulator.setReferenceValue(referenceValue); | ||
accumulator.setContext(0); | ||
|
||
return accumulator; | ||
} | ||
|
||
@Override | ||
public Accumulator<Object, Integer> getNextAccumulator() { | ||
if (this.accumulator == null) { | ||
return getInitialAccumulator(getResult()); | ||
} else { | ||
return accumulator; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"java.lettuce.core.RedisCommandTimeoutException": { | ||
"transformers": [{"transformerClassName": "cloud.filibuster.junit.server.core.transformers.RedisTimeoutExceptionTransformer"}], | ||
"pattern": "io.lettuce.core.api.sync.RedisStringCommands/(get|set)\\b" | ||
}} |
Oops, something went wrong.