Skip to content

Instantly share code, notes, and snippets.

View tomliversidge's full-sized avatar

Tom Liversidge tomliversidge

  • Tallinn, Estonia
View GitHub Profile
@tomliversidge
tomliversidge / tracker
Last active May 27, 2016 18:31
example akka implementation of a tracker manager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka.Actor;
namespace AkkaTrackerManager
{
class Program
@tomliversidge
tomliversidge / tm.cs
Created May 31, 2016 07:26
Tracker Manager with generic candidates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Configuration;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
@tomliversidge
tomliversidge / circle.yml
Created February 17, 2017 10:07
circleci database
machine:
environment:
PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
MIX_ENV: "ci"
services:
- postgresql
database:
override:
- createdb adatabasename
@tomliversidge
tomliversidge / circle.yml
Created February 17, 2017 14:05
heroku deployment
deployment:
staging:
branch: master
heroku:
appname: frozen-sauce-31481
@tomliversidge
tomliversidge / Persistence.cs
Last active April 1, 2017 19:17
no wrapping at all
public async Task InitAsync(IProvider provider, IContext context)
{
// other bits removed for brevity
await State.GetEventsAsync(Name, Index, callbackData =>
{
// dont wrap callbackData in anything (callbackData could be renamed to @event?)
Context.ReceiveAsync(callbackData).Wait();
Index++;
});
@tomliversidge
tomliversidge / ExampleActor.cs
Last active April 1, 2017 19:17
example actor
public async Task ReceiveAsync(IContext context)
{
switch (context.Message)
{
//...other handlers removed for brevity
case Multiply msg:
await Persistence.PersistEventAsync(new Multiplied { Amount = msg.Amount });
break;
case Multiplied msg:
_state.Value = _state.Value * msg.Amount;
@tomliversidge
tomliversidge / RemovingRouteeTest.cs
Created April 2, 2017 17:16
Removing a routee test
[Fact]
public async void RoundRobinGroupRouter_RouteesCanBeRemoved()
{
var routee1 = Actor.Spawn(MyActorProps);
var routee2 = Actor.Spawn(MyActorProps);
var routee3 = Actor.Spawn(MyActorProps);
var routerProps = Router.NewRoundRobinGroup(Actor.FromProducer(() => new MyTestActor())
.WithMailbox(() => new TestMailbox()), routee1, routee2, routee3)
.WithMailbox(() => new TestMailbox());
@tomliversidge
tomliversidge / test.cs
Created April 2, 2017 19:14
Passing test
[Fact]
public async void RoundRobinGroupRouter_RouteesCanBeRemoved()
{
var routee1 = Actor.Spawn(MyActorProps);
var routee2 = Actor.Spawn(MyActorProps);
var routee3 = Actor.Spawn(MyActorProps);
var props = Router.NewRoundRobinGroup(MyActorProps, routee1, routee2, routee3)
.WithMailbox(() => new TestMailbox());
var router = Actor.Spawn(props);
@tomliversidge
tomliversidge / example2.cs
Created April 7, 2017 07:35
Example passing in EventStream
[Fact]
public void WhenActorStopped_MessagesGoToDeadLetter()
{
bool deadLetterEventReceived = false;
var eventStream = new EventStream();
eventStream.Subscribe<DeadLetterEvent>(@event => deadLetterEventReceived = true);
var props = Actor.FromProducer(() => new DoNothingActor())
.WithMailbox(() => new TestMailbox())
.WithEventStream(eventStream);
@tomliversidge
tomliversidge / example1.cs
Created April 7, 2017 07:37
Example using static
[Collection("EventStream Tests")]
public class DeadLetterTests
{
[Fact]
public void WhenActorStopped_MessagesGoToDeadLetter()
{
bool deadLetterEventReceived = false;
EventStream.Instance.Subscribe<DeadLetterEvent>(@event => deadLetterEventReceived = true);
var props = Actor.FromProducer(() => new DoNothingActor())