Skip to content

Instantly share code, notes, and snippets.

View cfstout's full-sized avatar

Clayton Stout cfstout

View GitHub Profile
@cfstout
cfstout / ThreadLocalExample.java
Created May 12, 2021 21:40
Example of ThreadLocal usage
class ThreadLocalExample {
public static void main(String[] args) {
ThreadLocal<String> threadLocal = ThreadLocal.withInitial(() -> "");
new Thread(() -> {
threadLocal.set("foo");
try {
Thread.sleep(100);
System.out.printf("Thread local from thread %s: %s%n", Thread.currentThread().getName(), threadLocal.get());
} catch (InterruptedException e) {
throw new RuntimeException(e);
@cfstout
cfstout / example_failure_config.md
Created May 12, 2021 21:37
Examples of config to define failure parameters

Config to fail calls to FooService-web

[{"serviceKey":"FooService-web","failureType":"ABORT","failureRate":1.0}]

Config to fail calls to FooService-web after 500ms, but does not actually call the service

[{"serviceKey":"FooService-web","failureType":"ABORT","failureRate":1.0, "durationMillis": 500}]

Config to introduce 500ms of latency to calls to FooService-web

[{"serviceKey":"FooService-web","failureType":"HANG","failureRate":1.0, "durationMillis": 500}]

Config to fail calls to FooService-web after 500ms after calling the service

@cfstout
cfstout / ServiceFailureIF.java
Created May 12, 2021 21:29
Failure injection config
@Immutable
public interface ServiceFailureIF {
String getServiceKey();
FailureType getFailureType();
@Default
default int getDurationMillis() {
return 0;
}
@cfstout
cfstout / list_to_map.scala
Created September 30, 2015 21:31
Function to translate a list to a map by index in scala
def setToMapByIndex(set: Set[String]): Map[Int, String] = {
val indices: List[Int] = (0 to set.size).toList
indices.zip(set).toMap
}