public async Task Flush()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(10).FlushInterval(100_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);
            var listener = new WriteApiTest.EventListener(_writeApi);

            var record = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record);
            _writeApi.Flush();
            listener.WaitToSuccess();

            var query = await _queryApi.Query(
                "from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(1, records.Count);
            Assert.AreEqual("h2o_feet", records[0].GetMeasurement());
            Assert.AreEqual(1, records[0].GetValue());
            Assert.AreEqual("level water_level", records[0].GetField());

            var instant = Instant.Add(Instant.FromUnixTimeMilliseconds(0), Duration.FromNanoseconds(1L));

            Assert.AreEqual(instant, records[0].GetTime());
        }
 private RefreshToken CreateToken()
 {
     return(new RefreshToken
     {
         Token = Guid.NewGuid().ToString(),
         ExpireTimestamp = Instant.Add(_clock.GetCurrentInstant(), Duration.FromDays(30))
     });
 }
 private TwoFactorAuthenticationIdentity(
     Identity identity,
     CreateTwoFactorAuthenticationIdentityDdto createTwoFactorAuthenticationIdentityDdto)
 {
     Identity     = identity;
     EmailAddress = createTwoFactorAuthenticationIdentityDdto.EmailAddress;
     TwoFactorAuthenticationType = createTwoFactorAuthenticationIdentityDdto.TwoFactorAuthenticationType;
     Token       = String.Random(40);
     TokenExpiry = Instant.Add(Clock.Now(), Duration.FromMinutes(20));
 }
 private RefreshToken(
     Session session,
     AuthenticationGrantTypeRefreshToken authenticationGrantTypeRefreshToken,
     out string token)
 {
     token   = String.Random(100);
     Session = session;
     AuthenticationGrantTypeRefreshToken = authenticationGrantTypeRefreshToken;
     Token       = token;
     TokenExpiry = Instant.Add(Clock.Now(), Duration.FromDays(2));
 }
示例#5
0
        public void Since_Later_ReturnsNone()
        {
            // Arrange
            var series = new SeriesDefinition();

            series.Values.AddRange(new[]
            {
                new InstantChartPoint(Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)), 10),
                new InstantChartPoint(Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(101)), 20),
                new InstantChartPoint(Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(102)), 30),
                new InstantChartPoint(Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(103)), 40)
            });

            // Act
            var filteredSeries = series.Since(Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(104)));

            // Assert
            Assert.AreEqual(0, filteredSeries.Values.Count);
        }
示例#6
0
        public void UpdateExistingOhlcPoints_Day_SameDayExisting_ModifiesSameDay()
        {
            // Act
            var existingPoint = new OhlcInstantChartPoint
            {
                X     = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)),
                Open  = 1000,
                Low   = 500,
                High  = 2000,
                Close = 1500
            };

            var existingPoints = new List <OhlcInstantChartPoint>()
            {
                existingPoint
            };

            var updatedPoints = new List <OhlcInstantChartPoint>
            {
                new OhlcInstantChartPoint
                {
                    X     = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)),
                    Open  = 1500,
                    Low   = 250,
                    High  = 2500,
                    Close = 2000
                }
            };

            // Arrange
            var component = new SeriesChartComponent(null);

            component.UpdateExistingOhlcPoints(existingPoints, updatedPoints, Resolution.Daily);

            // assert
            Assert.AreEqual(1000, existingPoint.Open);  // Original open should be used
            Assert.AreEqual(250, existingPoint.Low);    // Lowest low should be used
            Assert.AreEqual(2500, existingPoint.High);  // Highest high should be used
            Assert.AreEqual(2000, existingPoint.Close); // Latest close should be used

            Assert.AreEqual(0, updatedPoints.Count);    // Modified entry should be removed from updates
        }
        public void MappingRfc3339()
        {
            var data = "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,long,string,string,string,dateTime:RFC3339\n"
                       + "#group,false,false,false,false,false,false,false,false,false,true\n"
                       + "#default,_result,,,,,,,,,\n"
                       + ",result,table,_start,_stop,_time,_value,_field,_measurement,host,value\n"
                       + ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,10,free,mem,A,1970-01-01T00:00:10Z\n"
                       + ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,10,free,mem,A,\n";

            var tables = ParseFluxResponse(data);

            Assert.IsNotNull(tables.Count == 1);

            var records = tables[0].Records;

            Assert.That(records.Count == 2);

            Assert.That(Instant.Add(new Instant(), Duration.FromSeconds(10L))
                        .Equals(records[0].GetValueByKey("value")));
            Assert.IsNull(records[1].GetValueByKey("value"));
        }
示例#8
0
        public void UpdateExistingOhlcPoints_Day_OlderExisting_ModifiesNothing()
        {
            // Act
            var existingPoints = new List <OhlcInstantChartPoint>()
            {
                new OhlcInstantChartPoint
                {
                    X     = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(99)),
                    Open  = 1000,
                    Low   = 500,
                    High  = 2000,
                    Close = 1500
                }
            };


            var updatedPoints = new List <OhlcInstantChartPoint>
            {
                new OhlcInstantChartPoint
                {
                    X     = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)),
                    Open  = 1000,
                    Low   = 500,
                    High  = 2000,
                    Close = 1500
                }
            };

            // Arrange
            var component = new SeriesChartComponent(null);

            component.UpdateExistingOhlcPoints(existingPoints, updatedPoints, Resolution.Daily);

            // assert
            Assert.AreEqual(1, updatedPoints.Count);
        }
示例#9
0
 public void OperatorPlus_Equivalents()
 {
     Assert.AreEqual(threeMillion + Duration.Epsilon, threeMillion.Plus(Duration.Epsilon));
     Assert.AreEqual(threeMillion + Duration.Epsilon, Instant.Add(threeMillion, Duration.Epsilon));
 }
        internal IQueryable <Reservation> RunQuery(KitchenRpContext ctx)
        {
            var reservations = ctx.Reservations.Select(r => r);

            if (Statuses != null)
            {
                var reservations1 = reservations;
                var r             =
                    from innerst in ctx.StatusChanges
                    group innerst by innerst.Reservation.Id
                    into g
                    select new { change = g.Max(sc => sc.ChangedAt), id = g.Key }
                into min
                from res in reservations1
                join statuses in ctx.StatusChanges on res.Id equals statuses.Reservation.Id
                where statuses.ChangedAt == min.change && res.Id == min.id
                    select new TempResult {
                    R = res, S = statuses
                };

                var pred = PredicateBuilder.False <TempResult>();

                foreach (var status in Statuses)
                {
                    pred = pred.Or(sc => sc.S.CurrentStatus.Id == status.Id);
                }

                reservations = r.Where(pred).Select(t => t.R);
            }

            if (Owner != null)
            {
                reservations = reservations.Where(r => r.Owner.Id == Owner.Id);
            }

            if (Resource != null)
            {
                reservations = reservations
                               .Where(r => r.ReservedResource.IsActive)
                               .Where(r => r.ReservedResource.Id == Resource.Id);
            }

            if (From != null && To != null)
            {
                var bufferedFrom = Instant.Subtract(From.Value, Buffer);
                var bufferedTo   = Instant.Add(To.Value, Buffer);
                reservations = reservations
                               .Where(r => (bufferedFrom >= r.StartTime && bufferedFrom < r.EndTime) ||
                                      (bufferedTo > r.StartTime && bufferedTo <= r.EndTime) ||
                                      (bufferedFrom <= r.StartTime && bufferedTo >= r.EndTime)
                                      );
            }

            return(reservations
                   .Include(r => r.Owner)
                   .Include(r => r.ReservedResource)
                   .Include(r => r.StatusChanges)
                   .ThenInclude(r => r.CurrentStatus)
                   .Include(r => r.StatusChanges)
                   .ThenInclude(r => r.PreviousStatus));
        }
示例#11
0
        public void MergeCharts_SameSeriesUpdatedData_GetsMerged()
        {
            // Arrange
            var target = new Result
            {
                Charts = new Dictionary <string, ChartDefinition>
                {
                    {
                        "chart", new ChartDefinition
                        {
                            Series = new Dictionary <string, SeriesDefinition>
                            {
                                {
                                    "series", new SeriesDefinition
                                    {
                                        Values = new List <InstantChartPoint>
                                        {
                                            new InstantChartPoint
                                            {
                                                X = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)),
                                                Y = 100
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var source = new Result
            {
                Charts = new Dictionary <string, ChartDefinition>
                {
                    {
                        "chart", new ChartDefinition
                        {
                            Series = new Dictionary <string, SeriesDefinition>
                            {
                                {
                                    "series", new SeriesDefinition
                                    {
                                        Values = new List <InstantChartPoint>
                                        {
                                            new InstantChartPoint
                                            {
                                                X = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(100)),
                                                Y = 100
                                            },
                                            new InstantChartPoint
                                            {
                                                X = Instant.Add(Instant.FromUnixTimeTicks(0), Duration.FromDays(101)),
                                                Y = 100
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            // Act
            ResultUpdater.Merge(target, source);

            // Assert
            Assert.AreEqual(2, target.Charts["chart"].Series["series"].Values.Count);
        }