Skip to content

Commit

Permalink
* re-activating warmup logic
Browse files Browse the repository at this point in the history
* fixing tabs
  • Loading branch information
RagingKore committed Nov 7, 2023
1 parent 418e996 commit 9ef5f57
Show file tree
Hide file tree
Showing 30 changed files with 814 additions and 820 deletions.
20 changes: 16 additions & 4 deletions EventStore.Client.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<s:Int64 x:Key="/Default/CodeEditing/NullCheckPatterns/PatternTypeNamesToPriority/=JetBrains_002EReSharper_002EFeature_002EServices_002ECSharp_002ENullChecking_002EIfThenThrowPattern/@EntryIndexedValue">1000</s:Int64>
<s:Int64 x:Key="/Default/CodeEditing/NullCheckPatterns/PatternTypeNamesToPriority/=JetBrains_002EReSharper_002EFeature_002EServices_002ECSharp_002ENullChecking_002EPatternMatchingIfThenThrowPattern/@EntryIndexedValue">3000</s:Int64>
<s:Int64 x:Key="/Default/CodeEditing/NullCheckPatterns/PatternTypeNamesToPriority/=JetBrains_002EReSharper_002EFeature_002EServices_002ECSharp_002ENullChecking_002EThrowExpressionNullCheckPattern/@EntryIndexedValue">5000</s:Int64>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeDefaultValueWhenTypeEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeDefaultValueWhenTypeNotEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeNamespaceBody/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeObjectCreationWhenTypeEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeObjectCreationWhenTypeNotEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue"></s:String>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexRemoved">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=3D_0020Team/@EntryIndexedValue"></s:String>
Expand All @@ -23,30 +26,36 @@
&amp;lt;inspection_tool class="UnnecessaryReturnJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/IDEA_SETTINGS&gt;&lt;RIDER_SETTINGS&gt;&amp;lt;profile&amp;gt;
&amp;lt;Language id="CSS"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="EditorConfig"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="HTML"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="HTTP Request"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Handlebars"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Ini"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="JSON"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="JavaScript"&amp;gt;
&amp;lt;Language id="Jade"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="JavaScript"&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Markdown"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
Expand All @@ -64,9 +73,9 @@
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="XML"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="yaml"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
Expand All @@ -77,6 +86,8 @@

<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">EventStore</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/CONSTRUCTOR_OR_DESTRUCTOR_BODY/@EntryValue">ExpressionBody</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_INTERNAL_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_PRIVATE_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/LOCAL_FUNCTION_BODY/@EntryValue">ExpressionBody</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/METHOD_OR_OPERATOR_BODY/@EntryValue">ExpressionBody</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_DECLARED_IN/@EntryValue">BaseClass</s:String>
Expand Down Expand Up @@ -133,6 +144,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_EXPR_METHOD_ON_SINGLE_LINE/@EntryValue">IF_OWNER_IS_SINGLE_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_CASE_STATEMENT_ON_SAME_LINE/@EntryValue">IF_OWNER_IS_SINGLE_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/TYPE_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_DECLARATION_LPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ await _fixture.Client.CreateToStreamAsync(
completed.TrySetException(new Exception($"{dr}"));
},
userCredentials
)) {
)
) {
for (var i = 0; i < eventCount; i++)
await _fixture.StreamsClient.AppendToStreamAsync(
streamName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace EventStore.Client.Tests;

public static class EnumerableTaskExtensions {
[DebuggerStepThrough]
public static Task WhenAll(this IEnumerable<Task> source) => Task.WhenAll(source);
[DebuggerStepThrough]
public static Task WhenAll(this IEnumerable<Task> source) => Task.WhenAll(source);

[DebuggerStepThrough]
public static Task<T[]> WhenAll<T>(this IEnumerable<Task<T>> source) => Task.WhenAll(source);
[DebuggerStepThrough]
public static Task<T[]> WhenAll<T>(this IEnumerable<Task<T>> source) => Task.WhenAll(source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
namespace EventStore.Client.Tests;

public static class EventStoreClientExtensions {
public static Task CreateUserWithRetry(
this EventStoreUserManagementClient client, string loginName, string fullName, string[] groups, string password,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default
) =>
Policy.Handle<NotAuthenticatedException>()
.WaitAndRetryAsync(200, _ => FromMilliseconds(100))
.ExecuteAsync(
ct => client.CreateUserAsync(
loginName, fullName, groups, password,
userCredentials: userCredentials,
cancellationToken: ct
),
cancellationToken
);
public static Task CreateUserWithRetry(
this EventStoreUserManagementClient client, string loginName, string fullName, string[] groups, string password,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default
) =>
Policy.Handle<NotAuthenticatedException>()
.WaitAndRetryAsync(200, _ => FromMilliseconds(100))
.ExecuteAsync(
ct => client.CreateUserAsync(
loginName,
fullName,
groups,
password,
userCredentials: userCredentials,
cancellationToken: ct
),
cancellationToken
);
}
Original file line number Diff line number Diff line change
@@ -1,85 +1,89 @@
namespace EventStore.Client.Tests;

public static class EventStoreClientWarmupExtensions {
public static Task WarmUp(this EventStoreClient client) =>
DatabaseWarmup<EventStoreClient>.TryExecuteOnce(client, async ct => {
// if we can read from $users then we know that
// 1. the users exist
// 2. we are connected to leader if we require it
var users = await client
.ReadStreamAsync(
direction: Direction.Forwards,
streamName: "$users",
revision: StreamPosition.Start,
maxCount: 1,
userCredentials: TestCredentials.Root,
cancellationToken: ct)
.ToArrayAsync(ct);
public static Task WarmUp(this EventStoreClient client) =>
DatabaseWarmup<EventStoreClient>.TryExecuteOnce(
client,
async ct => {
// if we can read from $users then we know that
// 1. the users exist
// 2. we are connected to leader if we require it
var users = await client
.ReadStreamAsync(
direction: Direction.Forwards,
streamName: "$users",
revision: StreamPosition.Start,
maxCount: 1,
userCredentials: TestCredentials.Root,
cancellationToken: ct
)
.ToArrayAsync(ct);

if (users.Length == 0)
throw new ("System is not ready yet...");
if (users.Length == 0)
throw new("System is not ready yet...");

// the read from leader above is not enough to guarantee the next write goes to leader
_ = await client.AppendToStreamAsync(
streamName: "warmup",
expectedState: StreamState.Any,
eventData: Enumerable.Empty<EventData>(),
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
});
// the read from leader above is not enough to guarantee the next write goes to leader
_ = await client.AppendToStreamAsync(
streamName: "warmup",
expectedState: StreamState.Any,
eventData: Enumerable.Empty<EventData>(),
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
}
);

public static Task WarmUp(this EventStoreOperationsClient client) =>
DatabaseWarmup<EventStoreOperationsClient>.TryExecuteOnce(
client,
async ct => {
await client.RestartPersistentSubscriptions(
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
}
);
public static Task WarmUp(this EventStoreOperationsClient client) =>
DatabaseWarmup<EventStoreOperationsClient>.TryExecuteOnce(
client,
async ct => {
await client.RestartPersistentSubscriptions(
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
}
);

public static Task WarmUp(this EventStorePersistentSubscriptionsClient client) =>
DatabaseWarmup<EventStorePersistentSubscriptionsClient>.TryExecuteOnce(
client,
async ct => {
var id = Guid.NewGuid();
await client.CreateToStreamAsync(
streamName: $"warmup-stream-{id}",
groupName: $"warmup-group-{id}",
settings: new(),
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
}
);
public static Task WarmUp(this EventStorePersistentSubscriptionsClient client) =>
DatabaseWarmup<EventStorePersistentSubscriptionsClient>.TryExecuteOnce(
client,
async ct => {
var id = Guid.NewGuid();
await client.CreateToStreamAsync(
streamName: $"warmup-stream-{id}",
groupName: $"warmup-group-{id}",
settings: new(),
userCredentials: TestCredentials.Root,
cancellationToken: ct
);
}
);

public static Task WarmUp(this EventStoreProjectionManagementClient client) =>
DatabaseWarmup<EventStoreProjectionManagementClient>.TryExecuteOnce(
client,
async ct => {
_ = await client
.ListAllAsync(
userCredentials: TestCredentials.Root,
cancellationToken: ct
)
.Take(1)
.ToArrayAsync(ct);
public static Task WarmUp(this EventStoreProjectionManagementClient client) =>
DatabaseWarmup<EventStoreProjectionManagementClient>.TryExecuteOnce(
client,
async ct => {
_ = await client
.ListAllAsync(
userCredentials: TestCredentials.Root,
cancellationToken: ct
)
.Take(1)
.ToArrayAsync(ct);

// await client.RestartSubsystemAsync(userCredentials: TestCredentials.Root, cancellationToken: ct);
}
);
// await client.RestartSubsystemAsync(userCredentials: TestCredentials.Root, cancellationToken: ct);
}
);

public static Task WarmUp(this EventStoreUserManagementClient client) =>
DatabaseWarmup<EventStoreUserManagementClient>.TryExecuteOnce(
client,
async ct => _ = await client
.ListAllAsync(
userCredentials: TestCredentials.Root,
cancellationToken: ct
)
.Take(1)
.ToArrayAsync(ct)
);
public static Task WarmUp(this EventStoreUserManagementClient client) =>
DatabaseWarmup<EventStoreUserManagementClient>.TryExecuteOnce(
client,
async ct => _ = await client
.ListAllAsync(
userCredentials: TestCredentials.Root,
cancellationToken: ct
)
.Take(1)
.ToArrayAsync(ct)
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EventStore.Client;

public static class OperatingSystemExtensions {
public static bool IsWindows(this OperatingSystem operatingSystem) =>
operatingSystem.Platform != PlatformID.Unix
&& operatingSystem.Platform != PlatformID.MacOSX;
public static bool IsWindows(this OperatingSystem operatingSystem) =>
operatingSystem.Platform != PlatformID.Unix
&& operatingSystem.Platform != PlatformID.MacOSX;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
namespace EventStore.Client;

public static class ReadOnlyMemoryExtensions {
public static Position ParsePosition(this ReadOnlyMemory<byte> json) {
using var doc = JsonDocument.Parse(json);
public static Position ParsePosition(this ReadOnlyMemory<byte> json) {
using var doc = JsonDocument.Parse(json);

var checkPoint = doc.RootElement.GetString();
if (checkPoint is null)
throw new("Unable to parse Position, data is missing!");
var checkPoint = doc.RootElement.GetString();
if (checkPoint is null)
throw new("Unable to parse Position, data is missing!");

if (Position.TryParse(checkPoint, out var position) && position.HasValue)
return position.Value;
if (Position.TryParse(checkPoint, out var position) && position.HasValue)
return position.Value;

throw new("Unable to parse Position, invalid data!");
}
throw new("Unable to parse Position, invalid data!");
}

public static StreamPosition ParseStreamPosition(this ReadOnlyMemory<byte> json) {
using var doc = JsonDocument.Parse(json);
public static StreamPosition ParseStreamPosition(this ReadOnlyMemory<byte> json) {
using var doc = JsonDocument.Parse(json);

var checkPoint = doc.RootElement.GetString();
if (checkPoint is null)
throw new("Unable to parse Position, data is missing!");
var checkPoint = doc.RootElement.GetString();
if (checkPoint is null)
throw new("Unable to parse Position, data is missing!");

return StreamPosition.FromInt64(int.Parse(checkPoint));
}
return StreamPosition.FromInt64(int.Parse(checkPoint));
}
}
Loading

0 comments on commit 9ef5f57

Please sign in to comment.