Skip to content

Commit

Permalink
remove the LastOffset() (#380)
Browse files Browse the repository at this point in the history
The method name may be misleading. It does not indicate the last offset of the stream.
It indicates the last uncommited chunk id. This information is not necessary.
The user should use CommittedChunkId().

Signed-off-by: Gabriele Santomaggio <[email protected]>
  • Loading branch information
Gsantomaggio authored May 24, 2024
1 parent 5250316 commit 6ded862
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 54 deletions.
8 changes: 2 additions & 6 deletions RabbitMQ.Stream.Client/StreamStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 2.0, and the Mozilla Public License, version 2.0.
// Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

using System;
using System.Collections.Generic;

namespace RabbitMQ.Stream.Client;
Expand Down Expand Up @@ -29,12 +30,7 @@ public ulong FirstOffset()
return (ulong)r;
}

/// <summary>
/// The last offset in the stream.
///
/// return last offset in the stream
/// throws NoOffsetException if there is no first offset yet
/// </summary>
[Obsolete("LastOffset() is deprecated, please use CommittedChunkId instead.")]
public ulong LastOffset()
{
var r = _statistics.TryGetValue("last_chunk_id", out var value) ? value : -1;
Expand Down
4 changes: 0 additions & 4 deletions Tests/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,13 @@ public async void StreamStatus()
Assert.Throws<OffsetNotFoundException>(() => { stats.FirstOffset(); }
);

Assert.Throws<OffsetNotFoundException>(() => { stats.LastOffset(); }
);

Assert.Throws<OffsetNotFoundException>(() => { stats.CommittedChunkId(); }
);

await SystemUtils.PublishMessages(system, stream, 500, _testOutputHelper);
SystemUtils.Wait();
var statAfter = await system.StreamStats(stream);
Assert.Equal((ulong)0, statAfter.FirstOffset());
Assert.True(statAfter.LastOffset() > 0);
Assert.True(statAfter.CommittedChunkId() > 0);
await SystemUtils.CleanUpStreamSystem(system, stream);
}
Expand Down
84 changes: 42 additions & 42 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<MinVerSkip>true</MinVerSkip>
<Copyright>Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term Broadcom refers to Broadcom Inc. and/or its subsidiaries.</Copyright>
<Authors>Broadcom</Authors>
<Company>Broadcom Inc. and/or its subsidiaries.</Company>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AltCover" />
<PackageReference Include="AmqpNetLite" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="RabbitMQ.Client" />
<PackageReference Include="System.IO.Hashing" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RabbitMQ.Stream.Client\RabbitMQ.Stream.Client.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<None Include="Resources\**" CopyToOutputDirectory="PreserveNewest" LinkBase="TestFiles\" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<MinVerSkip>true</MinVerSkip>
<Copyright>Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term Broadcom refers to Broadcom Inc. and/or its subsidiaries.</Copyright>
<Authors>Broadcom</Authors>
<Company>Broadcom Inc. and/or its subsidiaries.</Company>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AltCover" />
<PackageReference Include="AmqpNetLite" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="RabbitMQ.Client" />
<PackageReference Include="System.IO.Hashing" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RabbitMQ.Stream.Client\RabbitMQ.Stream.Client.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<None Include="Resources\**" CopyToOutputDirectory="PreserveNewest" LinkBase="TestFiles\" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions docs/asciidoc/query-stream.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ The following methods are available:

- `FirstOffset()`: first offset in the stream
- `LastOffset()`: last offset in the stream
- `CommittedChunkId()`: the ID (offset) of the committed chunk (block of messages) in the stream.
It is the offset of the first message in the last chunk confirmed by a quorum of the stream cluster members (leader and replicas).
Expand Down

0 comments on commit 6ded862

Please sign in to comment.