Skip to content

Instantly share code, notes, and snippets.

@jconwell
jconwell / unique_email_addresses.gs
Created May 26, 2016
Google script to mine a unique list of email addresses from gmail
View unique_email_addresses.gs
function getEmails() {
// get all messages
var allAddresses = [];
var start = 0;
var emailCount = 500;
var doIt = true;
while (doIt) {
var emails = GmailApp.getMessagesForThreads(GmailApp.search('after:2012/9/1', start, emailCount))
start += emails.length;
doIt = emailCount == emails.length;
@jconwell
jconwell / README
Created Jul 14, 2015
Remotly Debug ElasticSearch in IntelliJ
View README
Pretty simple once you know how.
Step 1: In IntelliJ, create a new remote debug configuration. Name it something ElasticSearchy. All of the default values should be fine. The only thing you need to change is the Host value. If ElasticSearch is gonna be running locally, just use "localhost", otherwise use the IP address of the remote machine ElasticSearch is gonna run on
Step 2: When starting ElasticSearch, just add a -D argument with the standard java remote debug values like so:
bin/elasticsearch -D "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
ElasticSearch will start and if suspend is set to 'y', it'll pause execution until you have attached the IntelliJ debugger.
Step 3: In IntilliJ, run the remote debug configuration you created in step 1.
@jconwell
jconwell / ParrotActor.java
Created Dec 28, 2013
Testing utility actor to mimic the messaging behavior of an actor a test might interact with, but without actually creating an instance of the actor
View ParrotActor.java
package com.turbo.akka;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import java.util.HashMap;
import java.util.Map;
/**
@jconwell
jconwell / ChildCreationActor.java
Created Dec 27, 2013
Another utility actor used in unit testing. Use this when you need to refer to the actor being tested by its path, but don't want to create all the actor parent actors.
View ChildCreationActor.java
package com.turbo.akka;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
/**
* Utility actor that does nothing but take a Props and create
@jconwell
jconwell / ForwarderActor.java
Last active Jan 1, 2016
Akka actor that takes another ActorRef as a constructor argument, and forwards all incoming messages to the one passed in. This is useful for unit tests, where you can pass in a JavaTestKit instance to the constructor and all messages passed to this actor will be forwarded to the JavaTestKit instance.
View ForwarderActor.java
package com.turbo.akka;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
/**
* Simple actor that takes another actor and forwards all messages to it.
* Useful in unit testing for capturing and testing if a message was received.
* Simply pass in an Akka JavaTestKit probe into the constructor, and all messages
* that are sent to this actor are forwarded to the JavaTestKit probe
@jconwell
jconwell / akkaTestPatterns.md
Last active Sep 22, 2016
Unit and functional test patterns for Akka actors in Java
View akkaTestPatterns.md

AKKA Test Patterns for Java

NOTE: These patterns assume you have a working understanding of Akka's JavaTestKit

Testing Actors In Complete Isolation

AKKA is all about building hierarchies of actors to represent a system. I've found this is a great way to decompose, design, and if needed distribute a system. This means your system becomes a hierarchy of actors, where parent actors create and manage their child actors, and child actors either carry out some unit of work, and/or themselves become parent actors.

But this can be a bit of a pain when it comes to writing tests for your actors. For example, say we have an actor, actorA, who in turn creates one or more child actors. I could have actorA create its child actor(s) as part of its instantiation. This is attractive especially if I know the exact child actors its going to create.