Skip to content

Commit

Permalink
Merge pull request #1619 from Cratis:fix/namespace-id
Browse files Browse the repository at this point in the history
Remove namespace id as a concept
  • Loading branch information
einari authored Dec 17, 2024
2 parents d29a569 + 36e156c commit dfd16b6
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
using Cratis.Chronicle.Contracts.Observation;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Integration.Base;
using context = Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails_first_time.but_not_second_time.context;
using Humanizer;
using context = Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails.but_not_second_time.context;

namespace Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails_first_time;
namespace Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails;

[Collection(GlobalCollection.Name)]
public class but_not_second_time(context context) : Given<context>(context)
Expand All @@ -28,19 +29,20 @@ void Establish()

async Task Because()
{
var waitTime = 5.Seconds();
await ReactorObserver.WaitTillActive();
Observers[0].ShouldFail = true;
Observers[1].ShouldFail = false;
await EventStore.EventLog.Append(EventSourceId, Event);

// Wait for the first event to have been handled
await Tcs[0].Task.WaitAsync(TimeSpan.FromSeconds(5));
await Tcs[0].Task.WaitAsync(waitTime);

FailedPartitionsBeforeRetry = await EventStore.WaitForThereToBeFailedPartitions(ObserverId);
Jobs = await EventStore.WaitForThereToBeJobs();

// Wait for the second event to have been handled
await Tcs[1].Task.WaitAsync(TimeSpan.FromSeconds(5));
await Tcs[1].Task.WaitAsync(waitTime);
await EventStore.WaitForThereToBeNoJobs();

FailedPartitionsAfterRetry = await GetFailedPartitions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
using Cratis.Chronicle.Contracts.Observation;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Integration.Base;
using context = Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails_first_time.but_not_third_time.context;
using Humanizer;
using context = Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails.but_not_third_time.context;

namespace Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails_first_time;
namespace Cratis.Chronicle.Integration.Orleans.InProcess.for_Reactors.when_handling_event.and_it_fails;

[Collection(GlobalCollection.Name)]
public class but_not_third_time(context context) : Given<context>(context)
Expand All @@ -28,27 +29,29 @@ void Establish()

async Task Because()
{
var waitTime = 5.Seconds();

await ReactorObserver.WaitTillActive();
Observers[0].ShouldFail = true;
Observers[1].ShouldFail = true;
Observers[2].ShouldFail = false;
await EventStore.EventLog.Append(EventSourceId, Event);

// Wait for the first event to have been handled
await Tcs[0].Task.WaitAsync(TimeSpan.FromSeconds(60));
await Tcs[0].Task.WaitAsync(waitTime);

FailedPartitionsBeforeRetry = await EventStore.WaitForThereToBeFailedPartitions(ObserverId, TimeSpan.FromSeconds(60));
Jobs = await EventStore.WaitForThereToBeJobs(TimeSpan.FromSeconds(60));
FailedPartitionsBeforeRetry = await EventStore.WaitForThereToBeFailedPartitions(ObserverId, waitTime);
Jobs = await EventStore.WaitForThereToBeJobs(waitTime);

// Wait for the second event to have been handled
await Tcs[1].Task.WaitAsync(TimeSpan.FromSeconds(60));
await Tcs[1].Task.WaitAsync(waitTime);

FailedPartitionsBeforeRetry = await EventStore.WaitForThereToBeFailedPartitions(ObserverId, TimeSpan.FromSeconds(60));
Jobs = await EventStore.WaitForThereToBeJobs(TimeSpan.FromSeconds(60));
Jobs = await EventStore.WaitForThereToBeJobs(waitTime);

// Wait for the third event to have been handled
await Tcs[2].Task.WaitAsync(TimeSpan.FromSeconds(60));
await EventStore.WaitForThereToBeNoJobs(TimeSpan.FromSeconds(60));
await Tcs[2].Task.WaitAsync(waitTime);
await EventStore.WaitForThereToBeNoJobs(waitTime);

FailedPartitionsAfterRetry = await GetFailedPartitions();
}
Expand Down
6 changes: 1 addition & 5 deletions Source/Api/Namespaces/Namespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace Cratis.Api.Namespaces;
/// <summary>
/// Represents a namespace.
/// </summary>
/// <param name="Id">The <see cref="EventStoreNamespaceId"/> for the namespace.</param>
/// <param name="Name">The name of the namespace.</param>
/// <param name="Description">The description of the namespace.</param>
public record Namespace(
EventStoreNamespaceId Id,
EventStoreNamespaceName Name,
string Description);
public record Namespace(EventStoreNamespaceName Name, string Description);
2 changes: 1 addition & 1 deletion Source/Api/Namespaces/NamespaceQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public ISubject<IEnumerable<Namespace>> AllNamespaces([FromRoute] EventStoreName
var store = storage.GetEventStore(eventStore);
return new TransformingSubject<IEnumerable<NamespaceState>, IEnumerable<Namespace>>(
store.Namespaces.ObserveAll(),
_ => _.Select(_ => new Namespace(_.Id, _.Name, string.Empty)));
_ => _.Select(_ => new Namespace(_.Name, string.Empty)));
}
}
28 changes: 0 additions & 28 deletions Source/Kernel/Concepts/EventStoreNamespaceId.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Source/Kernel/Grains/EventSequences/EventSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public async Task<AppendManyResult> AppendMany(
causedBy));
}

return new AppendManyResult
return new()
{
CorrelationId = correlationId,
SequenceNumbers = results.Select(r => r.SequenceNumber).ToImmutableList(),
Expand Down
2 changes: 1 addition & 1 deletion Source/Kernel/Grains/Namespaces/Namespaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task Ensure(EventStoreNamespaceName @namespace)
if (State.Namespaces.Any(_ => _.Name == @namespace)) return;

logger.AddingNamespace(@namespace);
State.NewNamespaces.Add(new NamespaceState(EventStoreNamespaceId.Default, @namespace, DateTimeOffset.UtcNow));
State.NewNamespaces.Add(new NamespaceState(@namespace, DateTimeOffset.UtcNow));

var eventStoreName = (EventStoreName)this.GetPrimaryKeyString();
var channelId = ChannelId.Create(WellKnownBroadcastChannelNames.NamespaceAdded, eventStoreName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public async Task ReadStateAsync<T>(string stateName, GrainId grainId, IGrainSta
var eventStoreName = grainId.Key.ToString()!;
var eventStore = storage.GetEventStore(eventStoreName);

var namespaces = (await eventStore.Namespaces.GetAll()).Select(_ => new NamespaceState(_.Id, _.Name, _.Created)).ToList();
var namespaces = (await eventStore.Namespaces.GetAll()).Select(_ => new NamespaceState(_.Name, _.Created)).ToList();
if (namespaces.Find(_ => _.Name == EventStoreNamespaceName.Default) == default)
{
var @namespace = new NamespaceState(EventStoreNamespaceId.Default, EventStoreNamespaceName.Default, DateTimeOffset.UtcNow);
var @namespace = new NamespaceState(EventStoreNamespaceName.Default, DateTimeOffset.UtcNow);
namespaces.Add(@namespace);
await eventStore.Namespaces.Create(@namespace.Name, @namespace.Created);
}
Expand Down
7 changes: 1 addition & 6 deletions Source/Kernel/Storage.MongoDB/Namespaces/MongoDBNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ namespace Cratis.Chronicle.Storage.MongoDB.Namespaces;
/// </summary>
public class MongoDBNamespace
{
/// <summary>
/// Gets or sets the unique identifier.
/// </summary>
[BsonId]
public Guid Id { get; set; }

/// <summary>
/// Gets or sets the name of the namespace.
/// </summary>
[BsonId]
public string Name { get; set; } = string.Empty;

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions Source/Kernel/Storage.MongoDB/Namespaces/NamespaceStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public Task Create(EventStoreNamespaceName name, DateTimeOffset created)

var @namespace = new MongoDBNamespace
{
Id = Guid.NewGuid(),
Name = name,
Created = created
};
Expand All @@ -60,14 +59,14 @@ public async Task<IEnumerable<NamespaceState>> GetAll()
{
var result = await GetCollection().FindAsync(_ => true);
var namespaces = await result.ToListAsync();
return namespaces.Select(_ => new NamespaceState(_.Id, _.Name, _.Created));
return namespaces.Select(_ => new NamespaceState(_.Name, _.Created));
}

/// <inheritdoc/>
public ISubject<IEnumerable<NamespaceState>> ObserveAll() =>
new TransformingSubject<IEnumerable<MongoDBNamespace>, IEnumerable<NamespaceState>>(
GetCollection().Observe(),
_ => _.Select(_ => new NamespaceState(_.Id, _.Name, _.Created)));
_ => _.Select(_ => new NamespaceState(_.Name, _.Created)));

IMongoCollection<MongoDBNamespace> GetCollection() => database.GetCollection<MongoDBNamespace>(WellKnownCollectionNames.Namespaces);
}
6 changes: 1 addition & 5 deletions Source/Kernel/Storage/Namespaces/NamespaceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace Cratis.Chronicle.Storage.Namespaces;
/// <summary>
/// Represents the state of a namespace.
/// </summary>
/// <param name="Id"><see cref="EventStoreNamespaceId"/> for the namespace.</param>
/// <param name="Name"><see cref="EventStoreNamespaceName"/> for the namespace. </param>
/// <param name="Created">WHen it was created.</param>
public record NamespaceState(
EventStoreNamespaceId Id,
EventStoreNamespaceName Name,
DateTimeOffset Created);
public record NamespaceState(EventStoreNamespaceName Name, DateTimeOffset Created);
9 changes: 0 additions & 9 deletions Source/Workbench/Web/Api/Namespaces/AllNamespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ import Handlebars from 'handlebars';
const routeTemplate = Handlebars.compile('/api/event-store/{{eventStore}}/namespaces');

class AllNamespacesSortBy {
private _id: SortingActionsForObservableQuery<Namespace[]>;
private _name: SortingActionsForObservableQuery<Namespace[]>;
private _description: SortingActionsForObservableQuery<Namespace[]>;

constructor(readonly query: AllNamespaces) {
this._id = new SortingActionsForObservableQuery<Namespace[]>('id', query);
this._name = new SortingActionsForObservableQuery<Namespace[]>('name', query);
this._description = new SortingActionsForObservableQuery<Namespace[]>('description', query);
}

get id(): SortingActionsForObservableQuery<Namespace[]> {
return this._id;
}
get name(): SortingActionsForObservableQuery<Namespace[]> {
return this._name;
}
Expand All @@ -34,13 +29,9 @@ class AllNamespacesSortBy {
}

class AllNamespacesSortByWithoutQuery {
private _id: SortingActions = new SortingActions('id');
private _name: SortingActions = new SortingActions('name');
private _description: SortingActions = new SortingActions('description');

get id(): SortingActions {
return this._id;
}
get name(): SortingActions {
return this._name;
}
Expand Down
4 changes: 0 additions & 4 deletions Source/Workbench/Web/Api/Namespaces/Namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
/* eslint-disable sort-imports */
// eslint-disable-next-line header/header
import { field } from '@cratis/fundamentals';
import { Guid } from '@cratis/fundamentals';

export class Namespace {

@field(Guid)
id!: Guid;

@field(String)
name!: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { withViewModel } from '@cratis/applications.react.mvvm';
import { NamespacesViewModel } from './NamespacesViewModel';
import { AllNamespaces, AllNamespacesArguments, Namespace } from 'Api/Namespaces';
import { AllNamespaces, AllNamespacesArguments } from 'Api/Namespaces';
import { type EventStoreAndNamespaceParams } from 'Shared';
import strings from 'Strings';
import { DataPage, MenuItem } from 'Components';
Expand All @@ -13,8 +13,6 @@ import { useParams } from 'react-router-dom';
import { useDialogRequest } from '@cratis/applications.react.mvvm/dialogs';
import { AddNamespace, AddNamespaceRequest, AddNamespaceResponse } from './AddNamespace';

const renderId = (namespace: Namespace) => namespace.id.toString();

export const Namespaces = withViewModel(NamespacesViewModel, ({ viewModel }) => {
const params = useParams<EventStoreAndNamespaceParams>();
const [AddNamespaceDialogWrapper] = useDialogRequest<AddNamespaceRequest, AddNamespaceResponse>(AddNamespaceRequest);
Expand All @@ -28,7 +26,7 @@ export const Namespaces = withViewModel(NamespacesViewModel, ({ viewModel }) =>
title={strings.eventStore.general.types.title}
query={AllNamespaces}
queryArguments={queryArgs}
dataKey='id'
dataKey='name'
emptyMessage={strings.eventStore.general.namespaces.empty}>

<DataPage.MenuItems>
Expand All @@ -39,12 +37,6 @@ export const Namespaces = withViewModel(NamespacesViewModel, ({ viewModel }) =>
</DataPage.MenuItems>

<DataPage.Columns>
<Column
field='id'
style={{ width: '400px' }}
header={strings.eventStore.general.namespaces.columns.id}
sortable
body={renderId}/>
<Column field='name' header={strings.eventStore.general.namespaces.columns.name} sortable />
</DataPage.Columns>
</DataPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { INamespaces } from 'State/Namespaces';
import { DialogButtons, IDialogs } from '@cratis/applications.react.mvvm/dialogs';
import { DialogResult } from '@cratis/applications.react/dialogs';
import { type EventStoreAndNamespaceParams } from 'Shared';
import { Guid } from '@cratis/fundamentals';

@injectable()
export class ObserversViewModel {
Expand All @@ -19,7 +18,7 @@ export class ObserversViewModel {
private readonly _replay: Replay,
private readonly _dialogs: IDialogs,
@inject('params') private readonly _params: EventStoreAndNamespaceParams) {
this.currentNamespace = { id: Guid.empty, name: '', description: '' };
this.currentNamespace = { name: '', description: '' };

namespaces.currentNamespace.subscribe(namespace => {
this.currentNamespace = namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import { Namespace } from 'Api/Namespaces';
import { Replay } from 'Api/Observation';
import { Dialogs } from '@cratis/applications.react.mvvm/dialogs';
import { type EventStoreAndNamespaceParams } from 'Shared';
import { Guid } from '@cratis/fundamentals';

export class a_view_model {
constructor() {
this.namespaces = {
currentNamespace: new BehaviorSubject<Namespace>({ id: Guid.empty, name: '', description: '' }),
currentNamespace: new BehaviorSubject<Namespace>({ name: '', description: '' }),
setCurrentNamespace: sinon.stub(),
namespaces: new BehaviorSubject<Namespace[]>([])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { inject, injectable } from 'tsyringe';
import { Namespace } from 'Api/Namespaces';
import { INamespaces } from 'State/Namespaces';
import { Guid } from '@cratis/fundamentals';

export interface INamespaceSelectorProps {
onNamespaceSelected: (namespace: Namespace) => void;
Expand All @@ -26,7 +25,7 @@ export class NamespaceSelectorViewModel {
});
}

currentNamespace: Namespace = { id: Guid.empty, name: '', description: '' };
currentNamespace: Namespace = { name: '', description: '' };
namespaces: Namespace[] = [];

onNamespaceSelected(namespace: Namespace) {
Expand Down
3 changes: 1 addition & 2 deletions Source/Workbench/Web/State/Namespaces/Namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import { BehaviorSubject } from 'rxjs';
import { CurrentNamespaceChanged } from './CurrentNamespaceChanged';
import { INamespaces } from './INamespaces';
import { type EventStoreAndNamespaceParams } from 'Shared';
import { Guid } from '@cratis/fundamentals';

/**
* Represents an implementation of {@link INamespaces}
*/
@injectable()
export class Namespaces implements INamespaces {
private _currentNamespace: BehaviorSubject<Namespace> = new BehaviorSubject({ id: Guid.empty, name: '', description: '' });
private _currentNamespace: BehaviorSubject<Namespace> = new BehaviorSubject({ name: '', description: '' });
private _namespaces: BehaviorSubject<Namespace[]> = new BehaviorSubject<Namespace[]>([]);

constructor(
Expand Down
Loading

0 comments on commit dfd16b6

Please sign in to comment.