Skip to content

Instantly share code, notes, and snippets.

View maxtomassi's full-sized avatar

Massimiliano Tomassi maxtomassi

View GitHub Profile
@maxtomassi
maxtomassi / simulate_fault_wiremock_standalone.json
Created November 20, 2014 08:32
Simulate slow API with WireMock standalone
{
"request": {
"method": "GET",
"url": "/videos"
},
"response": {
"status": 200,
"bodyFileName": "videos.json",
"fixedDelayMilliseconds": 2000
}
@maxtomassi
maxtomassi / simulate_fault_wiremock_unit_test.java
Created November 20, 2014 08:25
Simulating slow API with WireMock in unit test
stubFor(get(urlEqualTo("/videos")).willReturn(
aResponse()
.withStatus(200)
.withBodyFile("path/to/videos.json")
.withFixedDelay(2000)));
@maxtomassi
maxtomassi / videos_mapping.json
Created November 20, 2014 08:14
Mapping for video endpoint in standalone WireMock
{
"request": {
"method": "GET",
"url": "/videos"
},
"response": {
"status": 200,
"bodyFileName": "videos.json"
}
}
@maxtomassi
maxtomassi / stub_wiremock_unit_test.java
Last active August 29, 2015 14:10
Mock external API in unit test with WireMock
stubFor(get(urlEqualTo("/videos"))
.willReturn(aResponse()
.withStatus(200)
.withBodyFile("path/to/videos.json")));
@maxtomassi
maxtomassi / StopSparkStreaming.scala
Last active August 29, 2015 14:08
Gracefully stopping a Spark Streaming application
def main(args: Array[String]) {
// Prepare your environment
val ssc = new StreamingContext(conf, Seconds(batchDurationInSec))
// Do your processing
sys.ShutdownHookThread {
log.info("Gracefully stopping Spark Streaming Application")
@maxtomassi
maxtomassi / Main.java
Created October 23, 2014 01:17
Circuit breaker main
public class Main {
public static void main(String[] args) throws ExecutionException, InterruptedException {
for (int i = 0; i < 20; i++) {
String s1 = new CircuitBreakerCommand("World"+i).execute();
System.out.println(s1);
}
Hystrix.reset();
@maxtomassi
maxtomassi / CircuitBreakerCommand.java
Created October 23, 2014 01:15
Circuit breaker example
public class CircuitBreakerCommand extends HystrixCommand<String>{
private final String message;
public CircuitBreakerCommand(String message) {
super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("MyGroup"))
.andCommandPropertiesDefaults(
HystrixCommandProperties.Setter()
.withCircuitBreakerEnabled(true)
.withCircuitBreakerRequestVolumeThreshold(5)
aggregatedRDD.saveToCassandra("keySpaceName", "columnFamilyName", SomeColumns("word", "count"))
...
aggregatedRDD.foreach(element => store(element))
...
def store(element: YourModel): Unit = {
// 1. build your Cassandra statement
// 2. execute the statement
}
@maxtomassi
maxtomassi / gist:a4b806f0374e2a6f3821
Created September 25, 2014 07:45
spark_cassandra_output_format.scala
...
val casoutputCF = aggregatedRDD.map {
case (productId, saleCount) => {
val outColFamKey = Map("prod_id" -> ByteBufferUtil.bytes(productId))
val outKey: java.util.Map[String, ByteBuffer] = outColFamKey
var outColFamVal = new ListBuffer[ByteBuffer]
outColFamVal += ByteBufferUtil.bytes(saleCount)
val outVal: java.util.List[ByteBuffer] = outColFamVal
(outKey, outVal)