Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus committed Jun 30, 2016
2 parents cbf0bd7 + f6f049b commit 2d6abd3
Show file tree
Hide file tree
Showing 27 changed files with 884 additions and 249 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ want to build the code.
<img src="https://ci.appveyor.com/api/projects/status/51yvhvbd909e4o82/branch/develop?svg=true" />
</a>
</p>
<!--
<p>
<a href="https://codecov.io/github/rasmus/EventFlow?branch=develop">
   <img src="https://codecov.io/github/rasmus/EventFlow/coverage.svg?branch=develop" />
</a>
</p>
-->
</td>
</tr>
</table>
Expand Down Expand Up @@ -215,9 +217,10 @@ several areas that you could help out with.
EvenFlow has several tests that verify that its able to use the systems it
integrates with correctly.

* **Elasticsearch:** Set an environment variable named `ELASTICSEARCH_URL` with
the URL for the [Elasticsearch](https://www.elastic.co/) instance you would
like to use.
* **Elasticsearch:** [Elasticsearch](https://www.elastic.co/) is automatically
downloaded and run during the Elasticsearch integration tests from your `TEMP`
directory. Requires Java to be installed and the `JAVA_HOME` environment
variable set
* **EventStore:** [EventStore](https://geteventstore.com/) is automatically
downloaded and run during the EventStore integration tests from your `TEMP`
directory
Expand Down
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### New in 0.30 (not released yet)
### New in 0.31 (not released yet)

* New: EventFlow can now be configured to throw exceptions thrown by subscribers
by `options.Configure(c => c.ThrowSubscriberExceptions = true)`
* New: Added an `ICommandScheduler` for easy scheduling of commands

### New in 0.30.2019 (released 2016-06-16)

* Breaking: To simplify the EventFlow NuGet package structure, the two NuGet
packages `EventFlow.EventStores.MsSql` and `EventFlow.ReadStores.MsSql` have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="EventStoreRunner.cs" />
<Compile Include="Extensions\ProcessExtensions.cs" />
<Compile Include="IntegrationTests\EventStoreEventStoreTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TcpHelper.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventFlow.EventStores.EventStore\EventFlow.EventStores.EventStore.csproj">
Expand Down Expand Up @@ -352,4 +350,7 @@
<Paket>True</Paket>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>
</Project>
182 changes: 18 additions & 164 deletions Source/EventFlow.EventStores.EventStore.Tests/EventStoreRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using EventFlow.EventStores.EventStore.Tests.Extensions;
using EventFlow.Extensions;
using EventFlow.TestHelpers;
using EventStore.ClientAPI;
Expand All @@ -42,13 +38,15 @@
namespace EventFlow.EventStores.EventStore.Tests
{
[Category(Categories.Integration)]
public class EventStoreRunner
public class EventStoreRunner : Runner
{
private static readonly Dictionary<Version, Uri> EventStoreVersions = new Dictionary<Version, Uri>
{
{new Version(3, 4, 0), new Uri("http://download.geteventstore.com/binaries/EventStore-OSS-Win-v3.4.0.zip", UriKind.Absolute)},
{new Version(3, 3, 1), new Uri("http://download.geteventstore.com/binaries/EventStore-OSS-Win-v3.3.1.zip", UriKind.Absolute)}
};
protected override IEnumerable<SoftwareDescription> SoftwareDescriptions { get; } = new[]
{
new SoftwareDescription(new Version(3, 3, 1), new Uri("http://download.geteventstore.com/binaries/EventStore-OSS-Win-v3.3.1.zip", UriKind.Absolute)),
new SoftwareDescription(new Version(3, 4, 0), new Uri("http://download.geteventstore.com/binaries/EventStore-OSS-Win-v3.4.0.zip", UriKind.Absolute)),
};

protected override string SoftwareName { get; } = "EventStore";

public class EventStoreInstance : IDisposable
{
Expand Down Expand Up @@ -80,20 +78,26 @@ public async Task TestRunner()
}
}

public static async Task<EventStoreInstance> StartAsync()
public static Task<EventStoreInstance> StartAsync()
{
return new EventStoreRunner().InternalStartAsync();
}

private async Task<EventStoreInstance> InternalStartAsync()
{
var eventStoreVersion = EventStoreVersions.OrderByDescending(kv => kv.Key).First();
await InstallEventStoreAsync(eventStoreVersion.Key).ConfigureAwait(false);
var eventStoreVersion = SoftwareDescriptions.OrderByDescending(kv => kv.Version).First();
var eventStorePath = await InstallAsync(eventStoreVersion.Version).ConfigureAwait(false);

var tcpPort = TcpHelper.GetFreePort();
var httpPort = TcpHelper.GetFreePort();
var connectionStringUri = new Uri($"tcp://admin:changeit@{IPAddress.Loopback}:{tcpPort}");
var exePath = Path.Combine(eventStorePath, "EventStore.ClusterNode.exe");

IDisposable processDisposable = null;
try
{
processDisposable = StartExe(
Path.Combine(GetEventStorePath(eventStoreVersion.Key), "EventStore.ClusterNode.exe"),
exePath,
"'admin' user added to $users",
"--mem-db=True",
"--cluster-size=1",
Expand Down Expand Up @@ -137,155 +141,5 @@ public static async Task<EventStoreInstance> StartAsync()
connectionStringUri,
processDisposable);
}

private static IDisposable StartExe(
string exePath,
string initializationDone,
params string[] arguments)
{
var process = new Process
{
StartInfo = new ProcessStartInfo(exePath, string.Join(" ", arguments))
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
WorkingDirectory = Path.GetDirectoryName(exePath),
}
};
var exeName = Path.GetFileName(exePath);
process.OutputDataReceived += (sender, eventArgs) =>
{
if (string.IsNullOrEmpty(eventArgs.Data))
{
return;
}
Console.WriteLine("OUT - {0}: {1}", exeName, eventArgs.Data);
};
process.ErrorDataReceived += (sender, eventArgs) =>
{
if (string.IsNullOrEmpty(eventArgs.Data))
{
return;
}
Console.WriteLine("ERR - {0}: {1}", exeName, eventArgs.Data);
};
Action<Process> initializeProcess = p =>
{
Console.WriteLine($"{exeName} START =======================================");
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
};
process.WaitForOutput(initializationDone, initializeProcess);

return new DisposableAction(() =>
{
try
{
process.Kill();
process.WaitForExit(10000);
Console.WriteLine($"{process.ProcessName} KILLED =======================================");
}
catch (Exception e)
{
Console.WriteLine($"Failed to kill process: {e.Message}");
}
});
}

private static async Task InstallEventStoreAsync(Version version)
{
if (IsEventStoreInstalled(version))
{
Console.WriteLine($"EventStore v'{version}' is already installed");
return;
}

Console.WriteLine($"EventStore v{version} not installed, installing it");

var tempDownload = Path.Combine(
Path.GetTempPath(),
$"eventstore-v{version}-{Guid.NewGuid().ToString("N")}.zip");
try
{
await DownloadFileAsync(EventStoreVersions[version], tempDownload).ConfigureAwait(false);
var eventStorePath = GetEventStorePath(version);
ExtractZipFile(tempDownload, eventStorePath);
}
finally
{
if (File.Exists(tempDownload))
{
File.Delete(tempDownload);
}
}
}

private static void ExtractZipFile(string zipSourcePath, string directoryDestinationPath)
{
Console.WriteLine($"Extracting '{zipSourcePath}' to '{directoryDestinationPath}'");

if (!Directory.Exists(directoryDestinationPath))
{
Directory.CreateDirectory(directoryDestinationPath);
}

ZipFile.ExtractToDirectory(zipSourcePath, directoryDestinationPath);
}

private static bool IsEventStoreInstalled(Version version)
{
return Directory.Exists(GetEventStorePath(version));
}

private static string GetEventStorePath(Version version)
{
return Path.Combine(
Path.GetTempPath(),
$"eventflow-eventstore-v{version}");
}

private static async Task DownloadFileAsync(Uri sourceUri, string destinationPath)
{
if (File.Exists(destinationPath))
{
throw new ArgumentException($"File '{destinationPath}' already exists");
}

Console.WriteLine($"Downloading '{sourceUri}' to '{destinationPath}'");

using (var httpClient = new HttpClient())
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, sourceUri))
using (var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage).ConfigureAwait(false))
{
if (!httpResponseMessage.IsSuccessStatusCode)
{
throw new HttpRequestException($"Failed to download '{sourceUri}' due to '{httpResponseMessage.StatusCode}'");
}

using (var sourceStream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
using (var destinationStream = new FileStream(destinationPath, FileMode.CreateNew))
{
await sourceStream.CopyToAsync(destinationStream).ConfigureAwait(false);
}
}
}

private class DisposableAction : IDisposable
{
private readonly Action _action;

public DisposableAction(Action action)
{
_action = action;
}

public void Dispose()
{
_action();
}
}
}
}

This file was deleted.

Loading

0 comments on commit 2d6abd3

Please sign in to comment.