Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Cratis/Chronicle
Browse files Browse the repository at this point in the history
  • Loading branch information
einari committed Jan 25, 2025
2 parents aaba8a3 + b3be492 commit 05031d0
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 81 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"

env:
DOTNET8_VERSION: "8.0.405"
DOTNET_VERSION: "9.0.x"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '42 21 * * 4'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: csharp
build-mode: none
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .Net
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ env.DOTNET8_VERSION }}
${{ env.DOTNET_VERSION }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<PackageVersion Include="Mono.Cecil" Version="0.11.6" />
<PackageVersion Include="NJsonSchema" Version="11.1.0" />
<PackageVersion Include="Polly.Core" Version="8.5.1" />
<PackageVersion Include="protobuf-net.BuildTools" Version="3.2.33">
<PackageVersion Include="protobuf-net.BuildTools" Version="3.2.46">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ static void ConfigureChronicle(this ISiloBuilder builder, Action<IChronicleBuild
var grainFactory = sp.GetRequiredService<IGrainFactory>();
var services = sp.GetRequiredService<IServices>();

var loggerFactory = sp.GetRequiredService<ILoggerFactory>();

var connectionLifecycle = new ConnectionLifecycle(options.LoggerFactory.CreateLogger<ConnectionLifecycle>());
var connection = new Cratis.Chronicle.Orleans.InProcess.ChronicleConnection(connectionLifecycle, services, grainFactory);
var connection = new Cratis.Chronicle.Orleans.InProcess.ChronicleConnection(connectionLifecycle, services, grainFactory, loggerFactory);
return new ChronicleClient(connection, options);
});

Expand Down
7 changes: 5 additions & 2 deletions Source/Clients/Orleans.InProcess/ChronicleConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using Cratis.Chronicle.Connections;
using Cratis.Chronicle.Contracts.Clients;
using Microsoft.Extensions.Logging;
using Server::Cratis.Chronicle.Services.Clients;

namespace Cratis.Chronicle.Orleans.InProcess;
Expand All @@ -19,10 +20,12 @@ namespace Cratis.Chronicle.Orleans.InProcess;
/// <param name="lifecycle"><see cref="IConnectionLifecycle"/> for managing lifecycle.</param>
/// <param name="services"><see cref="IServices"/> to use.</param>
/// <param name="grainFactory"><see cref="IGrainFactory"/> for working with grains.</param>
/// <param name="loggerFactory"><see cref="ILoggerFactory"/> for creating loggers.</param>
public class ChronicleConnection(
IConnectionLifecycle lifecycle,
IServices services,
IGrainFactory grainFactory) : IChronicleConnection
IGrainFactory grainFactory,
ILoggerFactory loggerFactory) : IChronicleConnection
{
ConnectionService? _connectionService;

Expand Down Expand Up @@ -54,7 +57,7 @@ void ConnectIfNotConnected()

void Connect()
{
_connectionService = new ConnectionService(grainFactory);
_connectionService = new ConnectionService(grainFactory, loggerFactory.CreateLogger<ConnectionService>());
_connectionService.Connect(new()
{
ConnectionId = Lifecycle.ConnectionId,
Expand Down
7 changes: 7 additions & 0 deletions Source/Kernel/Grains.Interfaces/Projections/IProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public interface IProjection : IGrainWithStringKey
/// <param name="subscriber"><see cref="INotifyProjectionDefinitionsChanged"/> to subscribe.</param>
/// <returns>Awaitable task.</returns>
Task SubscribeDefinitionsChanged(INotifyProjectionDefinitionsChanged subscriber);

/// <summary>
/// Unsubscribe to changes in projection or pipeline definition changes.
/// </summary>
/// <param name="subscriber"><see cref="INotifyProjectionDefinitionsChanged"/> to subscribe.</param>
/// <returns>Awaitable task.</returns>
Task UnsubscribeDefinitionsChanged(INotifyProjectionDefinitionsChanged subscriber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Cratis.Chronicle.Grains.EventSequences.for_AppendedEventsQueue.when_enqueuing;

public class with_subscriber_that_throws_exception : given.a_single_subscriber_with_an_event_type
public class with_subscriber_that_throws_exception_on_first_handle : given.a_single_subscriber_with_an_event_type
{
AppendedEvent _appendedEvent;
EventSourceId _eventSourceId;
Expand All @@ -17,17 +17,25 @@ void Establish()
_eventSourceId = Guid.NewGuid();
_appendedEvent = _appendedEvent with { Context = EventContext.Empty with { EventSourceId = _eventSourceId } };

var callCount = 0;
_observer
.When(_ => _.Handle(Arg.Any<Key>(), Arg.Any<IEnumerable<AppendedEvent>>()))
.Do(_ => throw new Exception());
.Do(_ =>
{
switch (callCount++)
{
case 0:
throw new Exception();
case 1:
break;
}
});
}

async Task Because()
{
await _queue.Enqueue([_appendedEvent]);
await _queue.AwaitQueueDepletion();
await _queue.Enqueue([_appendedEvent]);
await _queue.AwaitQueueDepletion();
}

[Fact] void should_call_handle_on_observer_twice() => _handledEvents.Count.ShouldEqual(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts.Events;
using Cratis.Chronicle.Concepts.EventSequences;
using Cratis.Chronicle.Concepts.Keys;
using Cratis.Chronicle.Concepts.Observation;
using Cratis.Chronicle.Grains.Observation.States;

namespace Cratis.Chronicle.Grains.Observation.for_Observer.given;

Expand All @@ -14,6 +18,7 @@ void Establish()
{
subscription = new ObserverSubscription(_observerId, _observerKey, [], typeof(ObserverSubscriber), SiloAddress.Zero, null);
_observer.SetSubscription(subscription);
_observer.TransitionTo<Routing>();

_storageStats.ResetCounts();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts.Events;
using Cratis.Chronicle.Concepts.EventSequences;
using Cratis.Chronicle.Concepts.Keys;
using Cratis.Chronicle.Concepts.Observation;
using Cratis.Chronicle.Grains.Observation.States;

namespace Cratis.Chronicle.Grains.Observation.for_Observer.given;

Expand All @@ -16,6 +19,7 @@ void Establish()
{
subscription = new ObserverSubscription(_observerId, _observerKey, [event_type], typeof(IObserverSubscriber), SiloAddress.Zero, null);
_observer.SetSubscription(subscription);
_observer.TransitionTo<Routing>();

_storageStats.ResetCounts();
}
Expand Down
Loading

0 comments on commit 05031d0

Please sign in to comment.