public void TestAll()
        {
            var r = Lyrics.Parse <LineWithSpeaker>(TEST_DATA);
            var l = r.Lyrics;

            Assert.AreEqual(74, l.Lines.Count);
            Assert.AreEqual("", l.Lines[6].Content);
            Assert.AreEqual("全員: いっ]せーの!", l.Lines[7].Content);
            Assert.AreEqual(Timestamp.Create(2, 580), l.Lines[7].Timestamp);
            foreach (var item in l.Lines)
            {
                Assert.IsNotNull(item.Lyrics);
                Assert.IsNotNull(item.Speaker);
                CollectionAssert.Contains(new[]
                {
                    "全員",
                    "千和",
                    "真涼",
                    "姫香",
                    "愛衣",
                    "千和、真涼、姫香",
                    "千和、姫香",
                    "",
                }, item.Speaker);
            }
        }
示例#2
0
        public void GenerateSpan()
        {
            ZipkinEndpoint localEndpoint = new ZipkinEndpoint()
            {
                ServiceName = "tweetiebird"
            };

            var traceId  = "d239036e7d5cec116b562147388b35bf";
            var spanId   = "9cc1e3049173be09";
            var parentId = "8b03ab423da481c5";

            Dictionary <string, IAttributeValue> attributes    = new Dictionary <string, IAttributeValue>();
            IList <ITimedEvent <IAnnotation> >   annotations   = new List <ITimedEvent <IAnnotation> >();
            List <ITimedEvent <IMessageEvent> >  networkEvents = new List <ITimedEvent <IMessageEvent> >()
            {
                TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 433901068), new MessageEventBuilder(MessageEventType.RECEIVED, 0, 0, 0).SetCompressedMessageSize(7).Build()),
                TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 459486280), new MessageEventBuilder(MessageEventType.SENT, 0, 0, 0).SetCompressedMessageSize(13).Build())
            };

            ISpanData data = SpanData.Create(
                SpanContext.Create(
                    TraceId.FromBytes(Arrays.StringToByteArray(traceId)),
                    SpanId.FromBytes(Arrays.StringToByteArray(spanId)),
                    TraceOptions.FromBytes(new byte[] { 1 })),
                SpanId.FromBytes(Arrays.StringToByteArray(parentId)),
                true,                               /* hasRemoteParent */
                "Recv.helloworld.Greeter.SayHello", /* name */
                Timestamp.Create(EPOCH_SECONDS + 1505855794, 194009601) /* startTimestamp */,
                Attributes.Create(attributes, 0 /* droppedAttributesCount */),
                TimedEvents <IAnnotation> .Create(annotations, 0 /* droppedEventsCount */),
                TimedEvents <IMessageEvent> .Create(networkEvents, 0 /* droppedEventsCount */),
                LinkList.Create(new List <ILink>(), 0 /* droppedLinksCount */),
                null, /* childSpanCount */
                Status.OK,
                Timestamp.Create(EPOCH_SECONDS + 1505855799, 465726528) /* endTimestamp */);

            var handler = new TraceExporterHandler(new TraceExporterOptions()
            {
                UseShortTraceIds = false
            });
            var result = handler.GenerateSpan(data, localEndpoint);

            var zspan = ZipkinSpan.NewBuilder()
                        .TraceId(traceId)
                        .ParentId(parentId)
                        .Id(spanId)
                        .Kind(ZipkinSpanKind.SERVER)
                        .Name(data.Name)
                        .Timestamp(1505855794000000L + (194009601L / 1000))
                        .Duration(
                (1505855799000000L + (465726528L / 1000))
                - (1505855794000000L + (194009601L / 1000)))
                        .LocalEndpoint(localEndpoint)
                        .AddAnnotation(1505855799000000L + (433901068L / 1000), "RECEIVED")
                        .AddAnnotation(1505855799000000L + (459486280L / 1000), "SENT")
                        .PutTag("census.status_code", "OK")
                        .Build();

            Assert.Equal(zspan, result);
        }
示例#3
0
        public ChaosListener(IListener inner, ChaosConfiguration configuration, Random random, ChaosConnector connector)
            : base(inner)
        {
            this.connector = connector;
            bool abort = random.NextDouble() < configuration.Abort.Percentage;

            if (!abort)
            {
                return;
            }

            Timestamp?abortAfter = null;

            if (configuration.Abort.Duration != null)
            {
                var abortTimeSpan = GetRandomValue(random, configuration.Abort.Duration);
                abortAfter = Timestamp.Create() + abortTimeSpan;
            }
            long?abortUpstreamBytes = null;

            if (configuration.Abort.UpstreamBytes != null)
            {
                abortUpstreamBytes = GetRandomValue(random, configuration.Abort.UpstreamBytes);
            }
            long?abortDownstreamBytes = null;

            if (configuration.Abort.DownstreamBytes != null)
            {
                abortDownstreamBytes = GetRandomValue(random, configuration.Abort.DownstreamBytes);
            }

            upstream   = new Channel(abortAfter, abortUpstreamBytes);
            downstream = new Channel(abortAfter, abortDownstreamBytes);
        }
示例#4
0
        public void Create_NegativeInteger_18446744073709551593()
        {
            Timestamp act = Timestamp.Create(-23);
            Timestamp exp = 18446744073709551593L;

            Assert.AreEqual(exp, act);
        }
示例#5
0
        public void Create_Length8ByteArray_Is578437695752307201()
        {
            Timestamp act = Timestamp.Create(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
            Timestamp exp = 578437695752307201L;

            Assert.AreEqual(exp, act);
        }
示例#6
0
        private void PlaneEquipmentStatusChanged(object sender, GameObjectEquipmentStatusChangedArgs args)
        {
            switch (args.Status)
            {
            case GameObjectEquipmentStatus.Added:
                m_worldEventsLog.AddEntry(new PlaneEquipmentAddedLogItem(
                                              Timestamp.Create(),
                                              (Plane)args.Equipment.RelatedGameObject,
                                              (PlaneEquipment)args.Equipment)
                {
                    IsDepriciated = true
                });
                break;

            case GameObjectEquipmentStatus.Removed:
                m_worldEventsLog.AddEntry(new PlaneEquipmentRemovedLogItem(
                                              Timestamp.Create(),
                                              (Plane)args.Equipment.RelatedGameObject,
                                              (PlaneEquipment)args.Equipment)
                {
                    IsDepriciated = true
                });
                break;

            default:
                throw new Exception("Unknown state");
            }
        }
示例#7
0
        private void TestRecordCumulative(IMeasure measure, IAggregation aggregation, params double[] values)
        {
            IView view = CreateCumulativeView(VIEW_NAME, measure, aggregation, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(1, 2);
            viewManager.RegisterView(view);
            ITagContext tags = tagger.EmptyBuilder.Put(KEY, VALUE).Build();

            foreach (double val in values)
            {
                PutToMeasureMap(statsRecorder.NewMeasureMap(), measure, val).Record(tags);
            }
            clock.Time = Timestamp.Create(3, 4);
            IViewData viewData = viewManager.GetView(VIEW_NAME);

            Assert.Equal(view, viewData.View);

            var tv = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(aggregation, measure, values) },
            },
                EPSILON);
        }
示例#8
0
        public void TestGetCumulativeViewDataWithoutBucketBoundaries()
        {
            IView view = CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = (Timestamp.Create(1, 0));
            viewManager.RegisterView(view);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.1)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            clock.Time = Timestamp.Create(3, 0);
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv       = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(MEAN, MEASURE_DOUBLE, 1.1) },
            },
                EPSILON);
        }
示例#9
0
#pragma warning disable SA1202 // Elements must be ordered by access
        public void TestGetCumulativeViewDataWithEmptyBucketBoundaries()
#pragma warning restore SA1202 // Elements must be ordered by access
        {
            IAggregation noHistogram =
                Distribution.Create(BucketBoundaries.Create(new List <double>()));
            IView view = CreateCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, new List <ITagKey>()
            {
                KEY
            });

            clock.Time = Timestamp.Create(1, 0);
            viewManager.RegisterView(view);
            statsRecorder
            .NewMeasureMap()
            .Put(MEASURE_DOUBLE, 1.1)
            .Record(tagger.EmptyBuilder.Put(KEY, VALUE).Build());
            clock.Time = Timestamp.Create(3, 0);
            IViewData viewData = viewManager.GetView(VIEW_NAME);
            var       tv       = TagValues.Create(new List <ITagValue>()
            {
                VALUE
            });

            StatsTestUtil.AssertAggregationMapEquals(
                viewData.AggregationMap,
                new Dictionary <TagValues, IAggregationData>()
            {
                { tv, StatsTestUtil.CreateAggregationData(noHistogram, MEASURE_DOUBLE, 1.1) }
            },
                EPSILON);
        }
示例#10
0
 public void Create()
 {
     Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 1, 100), Timestamp.Create(1, 100));
     Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 1, 100), Timestamp.Create(1100));
     Assert.AreEqual(new DateTime(1, 1, 1, 0, 1, 2, 100), Timestamp.Create(62, 100));
     Assert.AreEqual(new DateTime(1, 1, 1, 0, 1, 1, 100), Timestamp.Create(1, 1, 100));
 }
示例#11
0
        private void BonusAppliedHandler(object sender, BonusAppliedEventArgs args)
        {
            var entry = new BonusAppliedLogItem(Timestamp.Create(), args.Bonus.Id.Value, args.Plane.Id.Value);

            // marks as depritiated right now - this event has not to be transferred to new players
            entry.IsDepriciated = true;

            m_worldEventsLog.AddEntry(entry);
        }
 public void TimestampCreate_InvalidInput()
 {
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(-315576000001L, 0));
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(315576000001L, 0));
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(1, 1000000000));
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(1, -1));
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(-1, 1000000000));
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(-1, -1));
 }
示例#13
0
 public void Create_Length6ByteArray_throwsArgumentException()
 {
     ExceptionAssert.CatchArgumentException(() =>
     {
         Timestamp.Create(new byte[] { 1, 2, 3, 4, 5, 6 });
     },
                                            "bytes",
                                            "The byte array should have size of 8.");
 }
示例#14
0
        private void ExplosionHandler(object sender, ExplosionEventArgs args)
        {
            var entry = new GameObjectExplodedLogItem(Timestamp.Create(), args.Exploded.Id.Value);

            // marks as depritiated right now - this event has not to be transferred to new players
            entry.IsDepriciated = true;

            m_worldEventsLog.AddEntry(entry);
        }
        public void TimestampAddDuration()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(Timestamp.Create(1235, 223), timestamp.AddDuration(Duration.Create(1, 0)));
            Assert.Equal(Timestamp.Create(1234, 224), timestamp.AddDuration(Duration.Create(0, 1)));
            Assert.Equal(Timestamp.Create(1235, 224), timestamp.AddDuration(Duration.Create(1, 1)));
            Assert.Equal(Timestamp.Create(1236, 123), timestamp.AddDuration(Duration.Create(1, 999999900)));
        }
        public void TimestampSubtractTimestamp_NegativeResult()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(Duration.Create(-1, 0), timestamp.SubtractTimestamp(Timestamp.Create(1235, 223)));
            Assert.Equal(Duration.Create(0, -1), timestamp.SubtractTimestamp(Timestamp.Create(1234, 224)));
            Assert.Equal(Duration.Create(-1, -1), timestamp.SubtractTimestamp(Timestamp.Create(1235, 224)));
            Assert.Equal(Duration.Create(-1, -999999900), timestamp.SubtractTimestamp(Timestamp.Create(1236, 123)));
        }
示例#17
0
            public void Schedule()
            {
                List <OperationContinuation> continuations;

                // Calculate the budget. The timer is not exact, so we need to get the
                // time since the last time we calculated to recalculate the exact
                // budget we have.

                var time     = Timestamp.Create();
                var lastTime = new Timestamp(Interlocked.Exchange(ref this.lastTime, time.Ticks));
                var elapsed  = time - lastTime;

                long budget = (long)((elapsed.TotalSeconds * slices) * bandwidth);

                // Find out how much we've transferred and update the total transferred
                // value. We decrease the total transferred with the budget we had. However,
                // this would indefinitely increase the budget when the actual data
                // transferred is a lot lower than the bandwidth. We cap this at -budget.
                // We could just cap it at 0, but the problem is that the algorithm we're
                // using to throttle isn't exact, so a bit of leeway is helpful to spread
                // out the bandwidth usage.

                long oldTransferred;
                long newTransferred;

                do
                {
                    oldTransferred = transferred;
                    newTransferred = Math.Max(oldTransferred - budget, -budget);
                }while (Interlocked.CompareExchange(ref transferred, newTransferred, oldTransferred) != oldTransferred);

                // If we're still over budget, wait one more slice.

                if (newTransferred > budget)
                {
                    return;
                }

                // Get the list of continuations that were scheduled so we can execute them now.

                lock (syncRoot)
                {
                    if (this.continuations.Count == 0)
                    {
                        return;
                    }

                    continuations = new List <OperationContinuation>(this.continuations);
                    this.continuations.Clear();
                }

                foreach (var continuation in continuations)
                {
                    continuation.SetOutcome(OperationOutcome.Continue);
                }
            }
        public void TimestampAddDuration_Negative()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(Timestamp.Create(0, 0), timestamp.AddDuration(Duration.Create(-1234, -223)));
            Assert.Equal(Timestamp.Create(1233, 223), timestamp.AddDuration(Duration.Create(-1, 0)));
            Assert.Equal(Timestamp.Create(1233, 222), timestamp.AddDuration(Duration.Create(-1, -1)));
            Assert.Equal(Timestamp.Create(1232, 999999900), timestamp.AddDuration(Duration.Create(-1, -323)));
            Assert.Equal(Timestamp.Create(1200, 224), timestamp.AddDuration(Duration.Create(-33, -999999999)));
        }
        public void TimestampSubtractTimestamp()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(Duration.Create(1234, 223), timestamp.SubtractTimestamp(Timestamp.Create(0, 0)));
            Assert.Equal(Duration.Create(1, 0), timestamp.SubtractTimestamp(Timestamp.Create(1233, 223)));
            Assert.Equal(Duration.Create(1, 1), timestamp.SubtractTimestamp(Timestamp.Create(1233, 222)));
            Assert.Equal(Duration.Create(1, 323), timestamp.SubtractTimestamp(Timestamp.Create(1232, 999999900)));
            Assert.Equal(Duration.Create(33, 999999999), timestamp.SubtractTimestamp(Timestamp.Create(1200, 224)));
        }
示例#20
0
        private void TimerCallback(object state)
        {
            var time    = Timestamp.Create();
            var elapsed = time - lastTime;

            Update(elapsed, ref lastUpstream, ref averageUpstream, Upstream);
            Update(elapsed, ref lastDownstream, ref averageDownstream, Downstream);

            lastTime = time;
        }
        public void ConvertNanoTime()
        {
            mockClock.Setup(clock => clock.Now).Returns(timestamp);
            mockClock.Setup(clock => clock.NowNanos).Returns(1234L);

            ITimestampConverter timeConverter = TimestampConverter.Now(mockClock.Object);

            Assert.Equal(Timestamp.Create(1234, 10678), timeConverter.ConvertNanoTime(6234));
            Assert.Equal(Timestamp.Create(1234, 5444), timeConverter.ConvertNanoTime(1000));
            Assert.Equal(Timestamp.Create(1235, 0), timeConverter.ConvertNanoTime(999995556));
        }
        public void TimestampAddNanos_Negative()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(Timestamp.Create(1234, 0), timestamp.AddNanos(-223));
            Assert.Equal(Timestamp.Create(1233, 0), timestamp.AddNanos(-1000000223));
            Assert.Equal(Timestamp.Create(1232, 699799723), timestamp.AddNanos(-1300200500));
            Assert.Equal(Timestamp.Create(1229, 876544010), timestamp.AddNanos(-4123456213L));
            Assert.Equal(Timestamp.Create(1234L - 9223372036L - 1, 223 + 145224192), timestamp.AddNanos(Int64.MinValue))
            ;
        }
示例#23
0
        public void TestShouldCreateTimestamp_Option_None()
        {
            // Given
            var now = new DateTime(1800, 12, 21, 7, 7, 7);

            // When
            var result = Timestamp.Create(now);

            // Then
            Assert.IsTrue(result.IsNone);
        }
 public void TimestampCreate()
 {
     Assert.Equal(24, Timestamp.Create(24, 42).Seconds);
     Assert.Equal(42, Timestamp.Create(24, 42).Nanos);
     Assert.Equal(-24, Timestamp.Create(-24, 42).Seconds);
     Assert.Equal(42, Timestamp.Create(-24, 42).Nanos);
     Assert.Equal(315576000000L, Timestamp.Create(315576000000L, 999999999).Seconds);
     Assert.Equal(999999999, Timestamp.Create(315576000000L, 999999999).Nanos);
     Assert.Equal(-315576000000L, Timestamp.Create(-315576000000L, 999999999).Seconds);
     Assert.Equal(999999999, Timestamp.Create(-315576000000L, 999999999).Nanos);
 }
示例#25
0
        public void TestShouldCreateTimestamp_Option_Some()
        {
            // Given
            var now = new DateTime(2020, 12, 21, 7, 7, 7);

            // When
            var result = Timestamp.Create(now);

            // Then
            Assert.IsTrue(result.IsSome);
            Assert.AreEqual(now, result.GetOrException());
        }
示例#26
0
        public void TestShouldCreateTimestamp_Validate_Invalid()
        {
            // Given
            var now    = new DateTime(1850, 12, 21, 7, 7, 7);
            var origin = Origin.Create(Guids.Two(), nameof(TimestampTests), nameof(TestShouldCreateTimestamp_Validate_Invalid));

            // When
            var result = Timestamp.Create(now, origin);

            // Then
            Assert.IsTrue(result.IsInvalid());
        }
        public void TimestampAddNanos()
        {
            var timestamp = Timestamp.Create(1234, 223);

            Assert.Equal(timestamp, timestamp.AddNanos(0));
            Assert.Equal(Timestamp.Create(1235, 0), timestamp.AddNanos(999999777));
            Assert.Equal(Timestamp.Create(1235, 300200723), timestamp.AddNanos(1300200500));
            Assert.Equal(Timestamp.Create(1236, 0), timestamp.AddNanos(1999999777));
            Assert.Equal(Timestamp.Create(1243, 876544012), timestamp.AddNanos(9876543789L));
            Assert.Equal(Timestamp.Create(1234L + 9223372036L, 223 + 854775807), timestamp.AddNanos(Int64.MaxValue))
            ;
        }
示例#28
0
        public void TestShouldConvertTimestampToDateTime()
        {
            // Given
            var dateTime  = new DateTime(2020, 12, 21, 7, 7, 7);
            var timestamp = Timestamp.Create(dateTime).GetOrException();

            // When
            DateTime result = timestamp;

            // Then
            Assert.AreEqual(dateTime.ToString("f"), result.ToString("f"));
        }
 public void Timestamp_Equal()
 {
     // Positive tests.
     Assert.Equal(Timestamp.Create(0, 0), Timestamp.Create(0, 0));
     Assert.Equal(Timestamp.Create(24, 42), Timestamp.Create(24, 42));
     Assert.Equal(Timestamp.Create(-24, 42), Timestamp.Create(-24, 42));
     // Negative tests.
     Assert.NotEqual(Timestamp.Create(24, 42), Timestamp.Create(25, 42));
     Assert.NotEqual(Timestamp.Create(24, 42), Timestamp.Create(24, 43));
     Assert.NotEqual(Timestamp.Create(-24, 42), Timestamp.Create(-25, 42));
     Assert.NotEqual(Timestamp.Create(-24, 42), Timestamp.Create(-24, 43));
 }
        public void TestRegisterAndGetView()
        {
            MeasureToViewMap measureToViewMap = new MeasureToViewMap();
            TestClock        clock            = TestClock.Create(Timestamp.Create(10, 20));

            measureToViewMap.RegisterView(VIEW, clock);
            clock.Time = Timestamp.Create(30, 40);
            IViewData viewData = measureToViewMap.GetView(VIEW_NAME, clock, StatsCollectionState.ENABLED);

            Assert.Equal(VIEW, viewData.View);
            Assert.Empty(viewData.AggregationMap);
        }