Skip to content

Commit 32c13be

Browse files
committed
Port to 1.15.0
1 parent f235244 commit 32c13be

36 files changed

+801
-188
lines changed

RELEASE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#### Port
22
Aeron.NET has been ported against Java version:
3-
- Agrona: 0.9.29
4-
- Aeron: 1.14.0
3+
- Agrona: 0.9.30
4+
- Aeron: 1.15.0

driver/Aeron.Driver.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>Aeron.Driver</id>
5-
<version>1.14.0</version>
5+
<version>1.15.0</version>
66
<title>Aeron Driver</title>
77
<authors>Adaptive Financial Consulting Ltd.</authors>
88
<owners>Adaptive Financial Consulting Ltd.</owners>

driver/media-driver.jar

12.2 KB
Binary file not shown.

src/Adaptive.Aeron.Tests/ClientConductorTest.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ public class ClientConductorTest
5959
private SubscriptionReadyFlyweight SubscriptionReady;
6060
private OperationSucceededFlyweight OperationSuccess;
6161
private ErrorResponseFlyweight ErrorResponse;
62+
private ClientTimeoutFlyweight ClientTimeout;
6263

6364
private UnsafeBuffer PublicationReadyBuffer;
6465
private UnsafeBuffer SubscriptionReadyBuffer;
6566
private UnsafeBuffer OperationSuccessBuffer;
6667
private UnsafeBuffer ErrorMessageBuffer;
68+
private UnsafeBuffer ClientTimeoutBuffer;
6769

6870
private CopyBroadcastReceiver MockToClientReceiver;
6971

@@ -98,11 +100,13 @@ public void SetUp()
98100
SubscriptionReady = new SubscriptionReadyFlyweight();
99101
OperationSuccess = new OperationSucceededFlyweight();
100102
ErrorResponse = new ErrorResponseFlyweight();
103+
ClientTimeout = new ClientTimeoutFlyweight();
101104

102105
PublicationReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]);
103106
SubscriptionReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]);
104107
OperationSuccessBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]);
105108
ErrorMessageBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]);
109+
ClientTimeoutBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]);
106110

107111
CounterValuesBuffer = new UnsafeBuffer(new byte[COUNTER_BUFFER_LENGTH]);
108112
MockToClientReceiver = A.Fake<CopyBroadcastReceiver>();
@@ -144,6 +148,7 @@ public void SetUp()
144148
SubscriptionReady.Wrap(SubscriptionReadyBuffer, 0);
145149
OperationSuccess.Wrap(OperationSuccessBuffer, 0);
146150
ErrorResponse.Wrap(ErrorMessageBuffer, 0);
151+
ClientTimeout.Wrap(ClientTimeoutBuffer, 0);
147152

148153
PublicationReady.CorrelationId(CORRELATION_ID);
149154
PublicationReady.RegistrationId(CORRELATION_ID);
@@ -497,9 +502,51 @@ public void ShouldTimeoutInterServiceIfTooLongBetweenDoWorkCalls()
497502

498503
A.CallTo(() => MockClientErrorHandler(A<ConductorServiceTimeoutException>._)).MustHaveHappened();
499504

500-
Assert.True(Conductor.IsClosed());
505+
Assert.True(Conductor.IsTerminating());
501506
}
502507

508+
[Test]
509+
public void ShouldTerminateAndErrorOnClientTimeoutFromDriver()
510+
{
511+
SuppressPrintError = true;
512+
513+
Conductor.OnClientTimeout();
514+
515+
A.CallTo(() => MockClientErrorHandler.Invoke(A<Exception>._)).MustHaveHappened();
516+
517+
bool threwException = false;
518+
try
519+
{
520+
Conductor.DoWork();
521+
}
522+
catch (AgentTerminationException)
523+
{
524+
threwException = true;
525+
}
526+
527+
Assert.True(threwException);
528+
Assert.True(Conductor.IsTerminating());
529+
}
530+
531+
[Test]
532+
public void ShouldNotCloseAndErrorOnClientTimeoutForAnotherClientIdFromDriver()
533+
{
534+
WhenReceiveBroadcastOnMessage(
535+
ControlProtocolEvents.ON_CLIENT_TIMEOUT,
536+
ClientTimeoutBuffer,
537+
buffer =>
538+
{
539+
ClientTimeout.ClientId(Conductor.DriverListenerAdapter().ClientId + 1);
540+
return ClientTimeoutFlyweight.LENGTH;
541+
});
542+
543+
Conductor.DoWork();
544+
545+
A.CallTo(() => MockClientErrorHandler.Invoke(A<Exception>._)).MustNotHaveHappened();
546+
547+
Assert.False(Conductor.IsClosed());
548+
}
549+
503550
private void WhenReceiveBroadcastOnMessage(int msgTypeId, IMutableDirectBuffer buffer, Func<IMutableDirectBuffer, int> filler)
504551
{
505552
A.CallTo(() => MockToClientReceiver.Receive(A<MessageHandler>._)).Invokes(() =>

src/Adaptive.Aeron/Adaptive.Aeron.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
44
<PackageId>Aeron.Client</PackageId>
5-
<VersionPrefix>1.14.0</VersionPrefix>
5+
<VersionPrefix>1.15.0</VersionPrefix>
66
<Authors>Adaptive Financial Consulting Ltd.</Authors>
77
<Company>Adaptive Financial Consulting Ltd.</Company>
88
<Product>Aeron Client</Product>

src/Adaptive.Aeron/Aeron.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ public void Dispose()
173173
{
174174
_conductorInvoker.Dispose();
175175
}
176-
177-
_conductor.ClientClose();
178-
_ctx.Dispose();
179176
}
180177
}
181178

@@ -380,8 +377,11 @@ public static long ResourceLingerDurationNs()
380377
/// A number of the properties are for testing and should not be set by end users.
381378
///
382379
/// <b>Note:</b> Do not reuse instances of the context across different <seealso cref="Aeron"/> clients.
380+
///
381+
/// The context will be owned be <see cref="ClientConductor"/> after a successful
382+
/// <see cref="Aeron.Connect(Context)"/> and closed via <see cref="Aeron.Dispose"/>
383383
/// </summary>
384-
public class Context : IDisposable
384+
public class Context
385385
{
386386
private long _clientId;
387387
private bool _useConductorAgentInvoker = false;
@@ -536,16 +536,6 @@ static Context()
536536
/// </summary>
537537
public const string MDC_CONTROL_MODE = "control-mode";
538538

539-
/// <summary>
540-
/// Key for the session id for a publication or restricted subscription.
541-
/// </summary>
542-
public const string SESSION_ID_PARAM_NAME = "session-id";
543-
544-
/// <summary>
545-
/// Key for the linger timeout for a publication to wait around after draining in nanoseconds.
546-
/// </summary>
547-
public const string LINGER_PARAM_NAME = "linger";
548-
549539
/// <summary>
550540
/// Valid value for <seealso cref="MDC_CONTROL_MODE"/> when manual control is desired.
551541
/// </summary>
@@ -555,7 +545,17 @@ static Context()
555545
/// Valid value for <seealso cref="MDC_CONTROL_MODE_PARAM_NAME"/> when dynamic control is desired. Default value.
556546
/// </summary>
557547
public const string MDC_CONTROL_MODE_DYNAMIC = "dynamic";
548+
549+
/// <summary>
550+
/// Key for the session id for a publication or restricted subscription.
551+
/// </summary>
552+
public const string SESSION_ID_PARAM_NAME = "session-id";
558553

554+
/// <summary>
555+
/// Key for the linger timeout for a publication to wait around after draining in nanoseconds.
556+
/// </summary>
557+
public const string LINGER_PARAM_NAME = "linger";
558+
559559
/// <summary>
560560
/// Parameter name for channel URI param to indicate if a subscribed must be reliable or not. Value is boolean.
561561
/// </summary>
@@ -1223,8 +1223,10 @@ public IThreadFactory ThreadFactory()
12231223
/// </summary>
12241224
public void Dispose()
12251225
{
1226-
IoUtil.Unmap(_cncByteBuffer);
1226+
var cncByteBuffer = _cncByteBuffer;
12271227
_cncByteBuffer = null;
1228+
IoUtil.Unmap(cncByteBuffer);
1229+
12281230

12291231
_cncMetaDataBuffer?.Dispose();
12301232
_countersMetaDataBuffer?.Dispose();

src/Adaptive.Aeron/ChannelUri.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public override string ToString()
258258
/// <param name="termLength"> for the stream. </param>
259259
public void InitialPosition(long position, int initialTermId, int termLength)
260260
{
261+
if (position < 0 || 0 != (position & (FrameDescriptor.FRAME_ALIGNMENT - 1)))
262+
{
263+
throw new ArgumentException("invalid position: " + position);
264+
}
265+
261266
int bitsToShift = LogBufferDescriptor.PositionBitsToShift(termLength);
262267
int termId = LogBufferDescriptor.ComputeTermIdFromPosition(position, bitsToShift, initialTermId);
263268
int termOffset = (int)(position & (termLength - 1));

src/Adaptive.Aeron/ChannelUriStringBuilder.cs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using Adaptive.Aeron.LogBuffer;
4+
using static Adaptive.Aeron.LogBuffer.FrameDescriptor;
45

56
namespace Adaptive.Aeron
67
{
@@ -25,7 +26,6 @@ public class ChannelUriStringBuilder
2526
private string _tags;
2627
private string _alias;
2728
private bool? _reliable;
28-
private bool? _sparse;
2929
private int? _ttl;
3030
private int? _mtu;
3131
private int? _termLength;
@@ -34,6 +34,7 @@ public class ChannelUriStringBuilder
3434
private int? _termOffset;
3535
private int? _sessionId;
3636
private long? _linger;
37+
private bool? _sparse;
3738
private bool _isSessionIdTagged;
3839

3940
/// <summary>
@@ -277,30 +278,6 @@ public ChannelUriStringBuilder Reliable(bool? isReliable)
277278
return _reliable;
278279
}
279280

280-
/// <summary>
281-
/// Set to indicate if a term log buffer should be sparse on disk or not. Sparse saves space at the potential
282-
/// expense of latency.
283-
/// </summary>
284-
/// <param name="isSparse"> true if the term buffer log is sparse on disk. </param>
285-
/// <returns> this for a fluent API. </returns>
286-
/// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
287-
public ChannelUriStringBuilder Sparse(bool? isSparse)
288-
{
289-
_sparse = isSparse;
290-
return this;
291-
}
292-
293-
/// <summary>
294-
/// Get if a term log buffer should be sparse on disk or not. Sparse saves space at the potential expense of latency.
295-
/// </summary>
296-
/// <returns> true if the term buffer log is sparse on disk. </returns>
297-
/// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
298-
public bool? Sparse()
299-
{
300-
return _sparse;
301-
}
302-
303-
304281
/// <summary>
305282
/// Set the Time To Live (TTL) for a multicast datagram. Valid values are 0-255 for the number of hops the datagram
306283
/// can progress along.
@@ -345,7 +322,7 @@ public ChannelUriStringBuilder Mtu(int? mtu)
345322
throw new ArgumentException("MTU not in range 32-65504: " + mtu);
346323
}
347324

348-
if ((mtu & (FrameDescriptor.FRAME_ALIGNMENT - 1)) != 0)
325+
if ((mtu & (FRAME_ALIGNMENT - 1)) != 0)
349326
{
350327
throw new ArgumentException("MTU not a multiple of FRAME_ALIGNMENT: mtu=" + mtu);
351328
}
@@ -454,7 +431,7 @@ public ChannelUriStringBuilder TermOffset(int? termOffset)
454431
throw new ArgumentException("term offset not in range 0-1g: " + termOffset);
455432
}
456433

457-
if (0 != (termOffset & (FrameDescriptor.FRAME_ALIGNMENT - 1)))
434+
if (0 != (termOffset & (FRAME_ALIGNMENT - 1)))
458435
{
459436
throw new ArgumentException("term offset not multiple of FRAME_ALIGNMENT: " + termOffset);
460437
}
@@ -525,6 +502,29 @@ public ChannelUriStringBuilder Linger(long? lingerNs)
525502
return _linger;
526503
}
527504

505+
/// <summary>
506+
/// Set to indicate if a term log buffer should be sparse on disk or not. Sparse saves space at the potential
507+
/// expense of latency.
508+
/// </summary>
509+
/// <param name="isSparse"> true if the term buffer log is sparse on disk. </param>
510+
/// <returns> this for a fluent API. </returns>
511+
/// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
512+
public ChannelUriStringBuilder Sparse(bool? isSparse)
513+
{
514+
_sparse = isSparse;
515+
return this;
516+
}
517+
518+
/// <summary>
519+
/// Get if a term log buffer should be sparse on disk or not. Sparse saves space at the potential expense of latency.
520+
/// </summary>
521+
/// <returns> true if the term buffer log is sparse on disk. </returns>
522+
/// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
523+
public bool? Sparse()
524+
{
525+
return _sparse;
526+
}
527+
528528
/// <summary>
529529
/// Set the tags for a channel used by a publication or subscription. Tags can be used to identify or tag a
530530
/// channel so that a configuration can be referenced and reused.
@@ -606,6 +606,11 @@ public string Alias()
606606
/// <returns> this for a fluent API. </returns>
607607
public ChannelUriStringBuilder InitialPosition(long position, int initialTermId, int termLength)
608608
{
609+
if (position < 0 || 0 != (position & (FRAME_ALIGNMENT - 1)))
610+
{
611+
throw new ArgumentException("invalid position: " + position);
612+
}
613+
609614
int bitsToShift = LogBufferDescriptor.PositionBitsToShift(termLength);
610615

611616
_initialTermId = initialTermId;
@@ -657,21 +662,6 @@ public string Build()
657662
_sb.Append(Aeron.Context.MDC_CONTROL_MODE_PARAM_NAME).Append('=').Append(_controlMode).Append('|');
658663
}
659664

660-
if (null != _reliable)
661-
{
662-
_sb.Append(Aeron.Context.RELIABLE_STREAM_PARAM_NAME).Append('=').Append(_reliable).Append('|');
663-
}
664-
665-
if (null != _sparse)
666-
{
667-
_sb.Append(Aeron.Context.SPARSE_PARAM_NAME).Append('=').Append(_sparse).Append('|');
668-
}
669-
670-
if (null != _ttl)
671-
{
672-
_sb.Append(Aeron.Context.TTL_PARAM_NAME).Append('=').Append(_ttl.Value).Append('|');
673-
}
674-
675665
if (null != _mtu)
676666
{
677667
_sb.Append(Aeron.Context.MTU_LENGTH_PARAM_NAME).Append('=').Append(_mtu.Value).Append('|');
@@ -703,6 +693,16 @@ public string Build()
703693
_sb.Append(Aeron.Context.SESSION_ID_PARAM_NAME).Append('=').Append(PrefixTag(_isSessionIdTagged, _sessionId.Value)).Append('|');
704694
}
705695

696+
if (null != _ttl)
697+
{
698+
_sb.Append(Aeron.Context.TTL_PARAM_NAME).Append('=').Append(_ttl.Value).Append('|');
699+
}
700+
701+
if (null != _reliable)
702+
{
703+
_sb.Append(Aeron.Context.RELIABLE_STREAM_PARAM_NAME).Append('=').Append(_reliable).Append('|');
704+
}
705+
706706
if (null != _linger)
707707
{
708708
_sb.Append(Aeron.Context.LINGER_PARAM_NAME).Append('=').Append(_linger.Value).Append('|');
@@ -712,6 +712,11 @@ public string Build()
712712
{
713713
_sb.Append(Aeron.Context.ALIAS_PARAM_NAME).Append('=').Append(_alias).Append('|');
714714
}
715+
716+
if (null != _sparse)
717+
{
718+
_sb.Append(Aeron.Context.SPARSE_PARAM_NAME).Append('=').Append(_sparse).Append('|');
719+
}
715720

716721
char lastChar = _sb[_sb.Length - 1];
717722
if (lastChar == '|' || lastChar == '?')

0 commit comments

Comments
 (0)