Ejemplo n.º 1
0
        public async Task ClientInvokeCallback_SetActivityId()
        {
            Guid setActivityId = Guid.NewGuid();
            Guid activityId2   = Guid.NewGuid();

            RequestContextTestUtils.SetActivityId(activityId2);
            TestClientInvokeCallback callback = new TestClientInvokeCallback(output, setActivityId);

            this.runtimeClient.ClientInvokeCallback = callback.OnInvoke;
            IRequestContextProxyGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextProxyGrain>(GetRandomGrainId());

            Guid activityId = await grain.E2EActivityId();

            Assert.Equal(setActivityId, activityId); // "E2EActivityId Call#1"
            Assert.Equal(1, callback.TotalCalls);    // "Number of callbacks"

            RequestContextTestUtils.SetActivityId(Guid.Empty);
            RequestContext.Clear(); // Need this to clear out any old ActivityId value cached in RequestContext. Code optimization in RequestContext does not unset entry if Trace.CorrelationManager.ActivityId == Guid.Empty [which is the "normal" case]
            this.runtimeClient.ClientInvokeCallback = null;

            activityId = await grain.E2EActivityId();

            Assert.Equal(Guid.Empty, activityId);   // "E2EActivityId Call#2 == Zero"
            Assert.Equal(1, callback.TotalCalls);   // "Number of callbacks - should be unchanged"
        }
Ejemplo n.º 2
0
        public async Task RequestContext_ActivityId_CM_None_E2E()
        {
            Guid nullActivityId = Guid.Empty;

            IRequestContextTestGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            Guid result = grain.E2EActivityId().Result;

            Assert.Equal(nullActivityId, result);   // "E2E ActivityId should not exist"

            RequestContextTestUtils.SetActivityId(nullActivityId);
            Assert.Null(RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER));
            result = await grain.E2EActivityId();

            Assert.Equal(nullActivityId, result);   // "Null ActivityId propagated E2E incorrectly"
            RequestContext.Clear();

            RequestContextTestUtils.SetActivityId(nullActivityId);
            Assert.Null(RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER));
            for (int i = 0; i < Environment.ProcessorCount; i++)
            {
                result = await grain.E2EActivityId();

                Assert.Equal(nullActivityId, result);   // "Null ActivityId propagated E2E incorrectly"
            }
            RequestContext.Clear();
            RequestContextTestUtils.SetActivityId(nullActivityId);
            Assert.Null(RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER));
            result = await grain.E2EActivityId();

            Assert.Equal(nullActivityId, result);   // "Null ActivityId propagated E2E incorrectly"
            RequestContext.Clear();
        }
 private void TestCleanup()
 {
     RequestContextTestUtils.ClearActivityId();
     RequestContext.Clear();
     headers.Clear();
     this.fixture.RuntimeClient.ClientInvokeCallback = null;
 }
 private void TestCleanup()
 {
     RequestContextTestUtils.SetActivityId(Guid.Empty);
     RequestContext.Clear();
     headers.Clear();
     GrainClient.ClientInvokeCallback = null;
 }
Ejemplo n.º 5
0
 public RequestContextTests_Local(TestEnvironmentFixture fixture)
 {
     this.fixture                       = fixture;
     oldPropagateActivityId             = RequestContext.PropagateActivityId;
     RequestContext.PropagateActivityId = true;
     RequestContextTestUtils.SetActivityId(Guid.Empty);
     RequestContext.Clear();
     headers.Clear();
 }
Ejemplo n.º 6
0
        public RequestContextTests_Silo(ITestOutputHelper output, Fixture fixture)
        {
            this.output  = output;
            this.fixture = fixture;
            RequestContext.PropagateActivityId = true; // Client-side setting

            RequestContextTestUtils.SetActivityId(Guid.Empty);
            RequestContext.Clear();
        }
Ejemplo n.º 7
0
        public async Task RequestContext_ActivityId_Simple()
        {
            Guid activityId = Guid.NewGuid();
            IRequestContextTestGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            RequestContextTestUtils.SetActivityId(activityId);
            Guid result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId not propagated correctly"
        }
 public RequestContextTests_Local(TestEnvironmentFixture fixture)
 {
     this.fixture                       = fixture;
     oldPropagateActivityId             = RequestContext.PropagateActivityId;
     RequestContext.PropagateActivityId = true;
     RequestContextTestUtils.SetActivityId(Guid.Empty);
     RequestContext.Clear();
     headers.Clear();
     this.fixture.RuntimeClient.ClientInvokeCallback = null;
 }
Ejemplo n.º 9
0
        public RequestContextTests_Silo(ITestOutputHelper output, Fixture fixture)
        {
            this.output        = output;
            this.fixture       = fixture;
            this.runtimeClient = this.fixture.Client.ServiceProvider.GetRequiredService <OutsideRuntimeClient>();
            RequestContext.PropagateActivityId = true; // Client-side setting

            RequestContextTestUtils.ClearActivityId();
            RequestContext.Clear();
        }
Ejemplo n.º 10
0
        public async Task RequestContext_ActivityId_CM_DynamicChange_Server()
        {
            Guid activityId  = Guid.NewGuid();
            Guid activityId2 = Guid.NewGuid();

            const string PropagateActivityIdConfigKey = @"/OrleansConfiguration/Defaults/Tracing/@PropagateActivityId";
            var          changeConfig = new Dictionary <string, string>();

            IManagementGrain mgmtGrain = this.fixture.GrainFactory.GetGrain <IManagementGrain>(0);

            IRequestContextTestGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            RequestContextTestUtils.SetActivityId(activityId);
            Guid result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly"
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.FalseString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.NotEqual(activityId2, result); // "E2E ActivityId #2 should not have been propagated"
            Assert.Equal(Guid.Empty, result);     // "E2E ActivityId #2 should not have been propagated"
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.TrueString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId2, result);   // "E2E ActivityId #2 should have been propagated"
            RequestContext.Clear();

            RequestContextTestUtils.SetActivityId(activityId);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly after #2"
            RequestContext.Clear();
        }
Ejemplo n.º 11
0
        public async Task ClientInvokeCallback_CountCallbacks()
        {
            TestClientInvokeCallback callback = new TestClientInvokeCallback(output, Guid.Empty);

            this.runtimeClient.ClientInvokeCallback = callback.OnInvoke;
            IRequestContextProxyGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextProxyGrain>(GetRandomGrainId());

            RequestContextTestUtils.SetActivityId(Guid.Empty);
            Guid activityId = await grain.E2EActivityId();

            Assert.Equal(Guid.Empty, activityId);   // "E2EActivityId Call#1"
            Assert.Equal(1, callback.TotalCalls);   // "Number of callbacks"

            this.runtimeClient.ClientInvokeCallback = null;
            activityId = await grain.E2EActivityId();

            Assert.Equal(Guid.Empty, activityId);   // "E2EActivityId Call#2"
            Assert.Equal(1, callback.TotalCalls);   // "Number of callbacks - should be unchanged"
        }
Ejemplo n.º 12
0
        public async Task RequestContext_ActivityId_DynamicChange_Client()
        {
            Guid activityId  = Guid.NewGuid();
            Guid activityId2 = Guid.NewGuid();

            IRequestContextTestGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            RequestContextTestUtils.SetActivityId(activityId);
            Guid result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly"
            RequestContext.Clear();

            RequestContext.PropagateActivityId = false;
            output.WriteLine("Set RequestContext.PropagateActivityId={0}", RequestContext.PropagateActivityId);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.Equal(Guid.Empty, result);   // "E2E ActivityId #2 not not have been propagated"
            RequestContext.Clear();

            RequestContext.PropagateActivityId = true;
            output.WriteLine("Set RequestContext.PropagateActivityId={0}", RequestContext.PropagateActivityId);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId2, result);   // "E2E ActivityId #2 should have been propagated"
            RequestContext.Clear();

            RequestContextTestUtils.SetActivityId(activityId);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly after #2"
            RequestContext.Clear();
        }
Ejemplo n.º 13
0
        public void OnInvoke(InvokeMethodRequest request, IGrain grain)
        {
            // (NOT YET AVAILABLE) Interface name is available from: <c>grainReference.InterfaceName</c>
            // (NOT YET AVAILABLE) Method name is available from: <c>grainReference.GetMethodName(request.InterfaceId, request.MethodId)</c>
            // GrainId is available from: <c>grainReference.GrainId</c>
            // PrimaryKey is availabe from: <c>grainReference.GrainId.GetPrimaryKeyLong()</c> or <c>grainReference.GrainId.GetPrimaryKey()</c> depending on key type.
            // Call arguments are available from: <c>request.Arguments</c> array

            TotalCalls++;

            output.WriteLine("OnInvoke TotalCalls={0}", TotalCalls);

            try
            {
                output.WriteLine("OnInvoke called for Grain={0} PrimaryKey={1} GrainId={2} with {3} arguments",
                                 grain.GetType().FullName,
                                 ((GrainReference)grain).GrainId.GetPrimaryKeyLong(),
                                 ((GrainReference)grain).GrainId,
                                 request.Arguments != null ? request.Arguments.Length : 0);
            }
            catch (Exception exc)
            {
                output.WriteLine("**** Error OnInvoke for Grain={0} GrainId={1} with {2} arguments. Exception = {3}",
                                 grain.GetType().FullName,
                                 ((GrainReference)grain).GrainId,
                                 request.Arguments != null ? request.Arguments.Length : 0,
                                 exc);
            }

            if (setActivityId != Guid.Empty)
            {
                RequestContextTestUtils.SetActivityId(setActivityId);

                output.WriteLine("OnInvoke Set ActivityId={0}", setActivityId);
            }
            output.WriteLine("OnInvoke Current ActivityId={0}", RequestContextTestUtils.GetActivityId());
        }
        public void RequestContext_ActivityId_ExportToMessage()
        {
            Guid activityId     = Guid.NewGuid();
            Guid activityId2    = Guid.NewGuid();
            Guid nullActivityId = Guid.Empty;

            Message msg = new Message();

            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.SerializationManager);
            if (msg.RequestContextData != null)
            {
                foreach (var kvp in msg.RequestContextData)
                {
                    headers.Add(kvp.Key, kvp.Value);
                }
            }
            ;
            Assert.False(headers.ContainsKey(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER), "ActivityId should not be be present " + headers.ToStrings(separator: ","));
            TestCleanup();

            RequestContextTestUtils.SetActivityId(activityId);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.SerializationManager);
            if (msg.RequestContextData != null)
            {
                foreach (var kvp in msg.RequestContextData)
                {
                    headers.Add(kvp.Key, kvp.Value);
                }
            }
            ;
            Assert.True(headers.ContainsKey(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER), "ActivityId #1 should be present " + headers.ToStrings(separator: ","));
            object result = headers[RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER];

            Assert.NotNull(result);                                            // ActivityId #1 should not be null
            Assert.Equal(activityId, result);                                  // "E2E ActivityId #1 not propagated correctly"
            Assert.Equal(activityId, RequestContextTestUtils.GetActivityId()); // "Original E2E ActivityId #1 should not have changed"
            TestCleanup();

            RequestContextTestUtils.SetActivityId(nullActivityId);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.SerializationManager);
            if (msg.RequestContextData != null)
            {
                foreach (var kvp in msg.RequestContextData)
                {
                    headers.Add(kvp.Key, kvp.Value);
                }
            }
            ;
            Assert.False(headers.ContainsKey(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER), "Null ActivityId should not be present " + headers.ToStrings(separator: ","));
            TestCleanup();

            RequestContextTestUtils.SetActivityId(activityId2);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.SerializationManager);
            foreach (var kvp in msg.RequestContextData)
            {
                headers.Add(kvp.Key, kvp.Value);
            }
            ;
            Assert.True(headers.ContainsKey(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER), "ActivityId #2 should be present " + headers.ToStrings(separator: ","));
            result = headers[RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER];
            Assert.NotNull(result);                                             // ActivityId #2 should not be null
            Assert.Equal(activityId2, result);                                  // "E2E ActivityId #2 not propagated correctly"

            Assert.Equal(activityId2, RequestContextTestUtils.GetActivityId()); // "Original E2E ActivityId #2 should not have changed"
            TestCleanup();
        }
Ejemplo n.º 15
0
 public void Dispose()
 {
     RequestContextTestUtils.SetActivityId(Guid.Empty);
     RequestContext.Clear();
 }
Ejemplo n.º 16
0
        public void RequestContext_ActivityId_ExportImport()
        {
            Guid activityId     = Guid.NewGuid();
            Guid activityId2    = Guid.NewGuid();
            Guid nullActivityId = Guid.Empty;

            Message msg = new Message();

            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.DeepCopier);
            RequestContext.Clear();
            RequestContextExtensions.Import(msg.RequestContextData);
            var actId = RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER);

            Assert.Null(actId);
            TestCleanup();

            RequestContextTestUtils.SetActivityId(activityId);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.DeepCopier);
            RequestContext.Clear();
            RequestContextExtensions.Import(msg.RequestContextData);
            actId = RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER);
            if (msg.RequestContextData != null)
            {
                foreach (var kvp in msg.RequestContextData)
                {
                    headers.Add(kvp.Key, kvp.Value);
                }
            }
            ;
            Assert.NotNull(actId); // "ActivityId #1 should be present " + headers.ToStrings(separator: ",")
            object result = headers[RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER];

            Assert.NotNull(result);                                            // "ActivityId #1 should not be null"
            Assert.Equal(activityId, result);                                  // "E2E ActivityId #1 not propagated correctly"
            Assert.Equal(activityId, RequestContextTestUtils.GetActivityId()); // "Original E2E ActivityId #1 should not have changed"
            TestCleanup();

            RequestContextTestUtils.SetActivityId(nullActivityId);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.DeepCopier);
            RequestContext.Clear();
            RequestContextExtensions.Import(msg.RequestContextData);
            actId = RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER);
            Assert.Null(actId);
            TestCleanup();

            RequestContextTestUtils.SetActivityId(activityId2);
            msg = new Message();
            msg.RequestContextData = RequestContextExtensions.Export(this.fixture.DeepCopier);
            RequestContext.Clear();
            RequestContextExtensions.Import(msg.RequestContextData);
            actId = RequestContext.Get(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER);
            if (msg.RequestContextData != null)
            {
                foreach (var kvp in msg.RequestContextData)
                {
                    headers.Add(kvp.Key, kvp.Value);
                }
            }
            ;
            Assert.NotNull(actId);                                              // "ActivityId #2 should be present " + headers.ToStrings(separator: ",")
            result = headers[RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER];
            Assert.NotNull(result);                                             // "ActivityId #2 should not be null"
            Assert.Equal(activityId2, result);                                  // "E2E ActivityId #2 not propagated correctly

            Assert.Equal(activityId2, RequestContextTestUtils.GetActivityId()); // "Original E2E ActivityId #2 should not have changed"
            TestCleanup();
        }
Ejemplo n.º 17
0
 public void Dispose()
 {
     RequestContextTestUtils.ClearActivityId();
     RequestContext.Clear();
 }
Ejemplo n.º 18
0
 private void TestCleanup()
 {
     RequestContextTestUtils.ClearActivityId();
     RequestContext.Clear();
     headers.Clear();
 }
Ejemplo n.º 19
0
 public void Dispose()
 {
     RequestContextTestUtils.SetActivityId(Guid.Empty);
     GrainClient.ClientInvokeCallback = null;
     RequestContext.Clear();
 }