Skip to content

Instantly share code, notes, and snippets.

@bboyle1234
Last active July 26, 2018 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bboyle1234/51c4132e1223624d75ae7d0e80036d80 to your computer and use it in GitHub Desktop.
Save bboyle1234/51c4132e1223624d75ae7d0e80036d80 to your computer and use it in GitHub Desktop.
version: '2'
services:
eventstore1:
image: eventstore/eventstore
ports:
- 12113:2113/tcp
- 11113:1113/tcp
environment:
EVENTSTORE_CLUSTER_DNS: eventstore1
EVENTSTORE_CLUSTER_GOSSIP_PORT: '2112'
EVENTSTORE_CLUSTER_SIZE: '3'
EVENTSTORE_EXT_HTTP_PORT_ADVERTISE_AS: '12113'
EVENTSTORE_EXT_TCP_PORT_ADVERTISE_AS: '11113'
EVENTSTORE_EXT_IP: '127.0.0.1'
EVENTSTORE_EXT_IP_ADVERTISE_AS: '127.0.0.1'
EVENTSTORE_RUN_PROJECTIONS: 'All'
EVENTSTORE_START_STANDARD_PROJECTIONS: 'True'
entrypoint:
- /bin/bash
command:
- -c
- 'sed -i "/IntIpAdvertiseAs\:/d" /etc/eventstore/eventstore.conf && echo "IntIpAdvertiseAs: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && sed -i "/IntIp\:/d" /etc/eventstore/eventstore.conf && echo "IntIp: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && /entrypoint.sh'
eventstore2:
image: eventstore/eventstore
ports:
- 22113:2113/tcp
- 21113:1113/tcp
environment:
EVENTSTORE_CLUSTER_DNS: eventstore1
EVENTSTORE_CLUSTER_GOSSIP_PORT: '2112'
EVENTSTORE_CLUSTER_SIZE: '3'
EVENTSTORE_EXT_HTTP_PORT_ADVERTISE_AS: '22113'
EVENTSTORE_EXT_TCP_PORT_ADVERTISE_AS: '21113'
EVENTSTORE_EXT_IP: '127.0.0.1'
EVENTSTORE_EXT_IP_ADVERTISE_AS: '127.0.0.1'
EVENTSTORE_RUN_PROJECTIONS: 'All'
EVENTSTORE_START_STANDARD_PROJECTIONS: 'True'
entrypoint:
- /bin/bash
command:
- -c
- 'sed -i "/IntIpAdvertiseAs\:/d" /etc/eventstore/eventstore.conf && echo "IntIpAdvertiseAs: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && sed -i "/IntIp\:/d" /etc/eventstore/eventstore.conf && echo "IntIp: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && /entrypoint.sh'
eventstore3:
image: eventstore/eventstore
ports:
- 32113:2113/tcp
- 31113:1113/tcp
environment:
EVENTSTORE_CLUSTER_DNS: eventstore1
EVENTSTORE_CLUSTER_GOSSIP_PORT: '2112'
EVENTSTORE_CLUSTER_SIZE: '3'
EVENTSTORE_EXT_HTTP_PORT_ADVERTISE_AS: '32113'
EVENTSTORE_EXT_TCP_PORT_ADVERTISE_AS: '31113'
EVENTSTORE_EXT_IP: '127.0.0.1'
EVENTSTORE_EXT_IP_ADVERTISE_AS: '127.0.0.1'
EVENTSTORE_RUN_PROJECTIONS: 'All'
EVENTSTORE_START_STANDARD_PROJECTIONS: 'True'
entrypoint:
- /bin/bash
command:
- -c
- 'sed -i "/IntIpAdvertiseAs\:/d" /etc/eventstore/eventstore.conf && echo "IntIpAdvertiseAs: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && sed -i "/IntIp\:/d" /etc/eventstore/eventstore.conf && echo "IntIp: $$(hostname -i)" >> /etc/eventstore/eventstore.conf && /entrypoint.sh'
{
"members": Array[3][
{
"instanceId": "17703a26-4a05-4a55-9ceb-51a1c09e1045",
"timeStamp": "2018-07-26T23:51:29.247396Z",
"state": "Slave",
"isAlive": true,
"internalTcpIp": "172.18.0.5",
"internalTcpPort": 1112,
"internalSecureTcpPort": 0,
"externalTcpIp": "127.0.0.1",
"externalTcpPort": 31113,
"externalSecureTcpPort": 0,
"internalHttpIp": "172.18.0.5",
"internalHttpPort": 2112,
"externalHttpIp": "127.0.0.1",
"externalHttpPort": 32113,
"lastCommitPosition": 13193981,
"writerCheckpoint": 13211895,
"chaserCheckpoint": 13211895,
"epochPosition": 642,
"epochNumber": 1,
"epochId": "0d753a79-8852-434e-9da0-aac19de67cce",
"nodePriority": 0
},
{
"instanceId": "cc32a80c-a0a6-400e-8926-6274565a9ed2",
"timeStamp": "2018-07-26T23:51:29.558431Z",
"state": "Master",
"isAlive": true,
"internalTcpIp": "172.18.0.4",
"internalTcpPort": 1112,
"internalSecureTcpPort": 0,
"externalTcpIp": "127.0.0.1",
"externalTcpPort": 11113,
"externalSecureTcpPort": 0,
"internalHttpIp": "172.18.0.4",
"internalHttpPort": 2112,
"externalHttpIp": "127.0.0.1",
"externalHttpPort": 12113,
"lastCommitPosition": 13193981,
"writerCheckpoint": 13211895,
"chaserCheckpoint": 13211895,
"epochPosition": 642,
"epochNumber": 1,
"epochId": "0d753a79-8852-434e-9da0-aac19de67cce",
"nodePriority": 0
},
{
"instanceId": "b6626ff3-f5c1-496b-8f8a-6048f6767e8a",
"timeStamp": "2018-07-26T23:51:28.489078Z",
"state": "Slave",
"isAlive": true,
"internalTcpIp": "172.18.0.3",
"internalTcpPort": 1112,
"internalSecureTcpPort": 0,
"externalTcpIp": "127.0.0.1",
"externalTcpPort": 21113,
"externalSecureTcpPort": 0,
"internalHttpIp": "172.18.0.3",
"internalHttpPort": 2112,
"externalHttpIp": "127.0.0.1",
"externalHttpPort": 22113,
"lastCommitPosition": 13193981,
"writerCheckpoint": 13211895,
"chaserCheckpoint": 13211895,
"epochPosition": 642,
"epochNumber": 1,
"epochId": "0d753a79-8852-434e-9da0-aac19de67cce",
"nodePriority": 0
}
],
"serverIp": "172.18.0.4",
"serverPort": 2112
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net;
using System.Threading.Tasks;
using ESClusterSettings = EventStore.ClientAPI.ClusterSettings;
using ESConnection = EventStore.ClientAPI.EventStoreConnection;
using ESConnectionSettings = EventStore.ClientAPI.ConnectionSettings;
using ESUserCredentials = EventStore.ClientAPI.SystemData.UserCredentials;
namespace Apex.Events.EventStore.Test {
[TestClass]
public class EventStoreConnections {
[TestMethod]
public async Task ConnectToCluster() {
var tcs = new TaskCompletionSource<object>();
var settings = ESConnectionSettings.Create()
.EnableVerboseLogging()
.SetDefaultUserCredentials(new ESUserCredentials("admin", "changeit"))
.Build();
var clusterSettings = ESClusterSettings.Create()
.DiscoverClusterViaGossipSeeds()
.SetGossipSeedEndPoints(new[]{
new IPEndPoint(IPAddress.Loopback, 12113),
})
.Build();
var connection = ESConnection.Create(settings, clusterSettings, "test connection");
connection.Closed += (_, e) => {
// Happens after ten reconnection attempts.
tcs.SetException(new Exception("Closed"));
};
connection.Connected += (_, e) => {
// Does not happen
tcs.SetResult(null);
};
connection.Disconnected += (_, e) => {
// Does not happen
tcs.SetException(new Exception("Disconnected"));
};
connection.ErrorOccurred += (_, e) => {
// Does not happen
tcs.SetException(e.Exception);
};
connection.Reconnecting += (_, e) => {
// Happens 10 times
};
// This succeeds
await connection.ConnectAsync();
// This fails
await tcs.Task;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment