예제 #1
0
        public async Task Test_UndeployFunctionAsync(string jsonFileName, HttpStatusCode statusCode, Type exception)
        {
            using var response =
                      ResourceHelper.ReadResourceAsStream($@"Documents\Eventing\{jsonFileName}");
            var buffer = new byte[response.Length];

            response.Read(buffer, 0, buffer.Length);

            var httpResponseMessage = new HttpResponseMessage
            {
                StatusCode = statusCode,
                Content    = new ByteArrayContent(buffer)
            };

            var serviceMock = new Mock <IEventingFunctionService>();

            serviceMock.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <IRequestSpan>(), It.IsAny <IRequestSpan>(), It.IsAny <CancellationToken>(), null))
            .Returns(Task.FromResult(httpResponseMessage));

            using var tracer   = new RequestTracer();
            using var listener = new XUnitLoggerListener(_loggerFactory.CreateLogger <ThresholdTracerTests>());
            tracer.Start(listener);

            var manager = new EventingFunctionManager(serviceMock.Object,
                                                      new Mock <ILogger <EventingFunctionManager> >().Object, tracer);

            try
            {
                await manager.UndeployFunctionAsync("case_1_enrich_ips");
            }
            catch (Exception e)
            {
                Assert.True(e.GetType() == exception, $"Expected {e.GetType().Name} but was {exception.Name}");
            }
        }
예제 #2
0
        public async Task Test_FunctionStatus()
        {
            using var response =
                      ResourceHelper.ReadResourceAsStream(@"Documents\Eventing\200_ok_status.json");
            var buffer = new byte[response.Length];

            response.Read(buffer, 0, buffer.Length);

            var httpResponseMessage = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new ByteArrayContent(buffer)
            };

            var serviceMock = new Mock <IEventingFunctionService>();

            serviceMock.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <IRequestSpan>(), It.IsAny <IRequestSpan>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(httpResponseMessage));

            using var tracer   = new RequestTracer();
            using var listener = new XUnitLoggerListener(_loggerFactory.CreateLogger <ThresholdTracerTests>());
            tracer.Start(listener);

            var manager = new EventingFunctionManager(serviceMock.Object,
                                                      new Mock <ILogger <EventingFunctionManager> >().Object, tracer);

            var functionStatus = await manager.FunctionsStatus();

            Assert.Equal(1, functionStatus.NumEventingNodes);

            var function = functionStatus.Functions.First();

            Assert.Equal(EventingFunctionStatus.Undeployed, function.Status);
            Assert.Equal(EventingFunctionDeploymentStatus.Undeployed, function.DeploymentStatus);
            Assert.Equal(EventingFunctionProcessingStatus.Paused, function.ProcessingStatus);
            Assert.Equal(0, function.NumDeployedNodes);
            Assert.Equal(0, function.NumBootstrappingNodes);
            Assert.Equal("case_1_enrich_ips", function.Name);
        }
예제 #3
0
        public async Task Test_GetFunctionAsync_Ok()
        {
            using var response =
                      ResourceHelper.ReadResourceAsStream(@"Documents\Eventing\getfunction-response.json");
            var buffer = new byte[response.Length];

            response.Read(buffer, 0, buffer.Length);

            var httpResponseMessage = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new ByteArrayContent(buffer)
            };

            var serviceMock = new Mock <IEventingFunctionService>();

            serviceMock.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <IRequestSpan>(), It.IsAny <IRequestSpan>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(httpResponseMessage));

            using var tracer   = new RequestTracer();
            using var listener = new XUnitLoggerListener(_loggerFactory.CreateLogger <ThresholdTracerTests>());
            tracer.Start(listener);

            var manager = new EventingFunctionManager(serviceMock.Object,
                                                      new Mock <ILogger <EventingFunctionManager> >().Object, tracer);

            var eventingFunctions = await manager.GetFunctionAsync("case_1_enrich_ips");

            var eventingFunction = eventingFunctions;

            Assert.Equal("function OnUpdate(doc, meta) {\n  log('document', doc);\n  doc[\"ip_num_start\"] = get_numip_first_3_octets(doc[\"ip_start\"]);\n  doc[\"ip_num_end\"]   = get_numip_first_3_octets(doc[\"ip_end\"]);\n  tgt[meta.id]=doc;\n}\nfunction get_numip_first_3_octets(ip) {\n  var return_val = 0;\n  if (ip) {\n    var parts = ip.split('.');\n    //IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D\n    return_val = (parts[0]*(256*256*256)) + (parts[1]*(256*256)) + (parts[2]*256) + parseInt(parts[3]);\n    return return_val;\n  }\n}", eventingFunction.Code);
            Assert.Equal("UhEbm2", eventingFunction.FunctionInstanceId);
            Assert.Equal("evt-7.0.0-5071-ee", eventingFunction.Version);
            Assert.False(eventingFunction.EnforceSchema);
            Assert.Equal(2908133798, eventingFunction.HandlerUuid);
        }