Ejemplo n.º 1
0
 public virtual void TestServiceStopFromInited()
 {
     TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                              ("ServiceManager");
     // Add services
     for (int i = 0; i < NumOfServices; i++)
     {
         TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                                 (i);
         serviceManager.AddTestService(service);
     }
     TestCompositeService.CompositeServiceImpl[] services = Collections.ToArray
                                                                (serviceManager.GetServices(), new TestCompositeService.CompositeServiceImpl[0]);
     serviceManager.Init(new Configuration());
     serviceManager.Stop();
     if (StopOnlyStartedServices)
     {
         //this policy => no services were stopped
         AssertInState(Service.STATE.Inited, services);
     }
     else
     {
         AssertInState(Service.STATE.Stopped, services);
     }
 }
Ejemplo n.º 2
0
        public virtual void TestServiceStop()
        {
            TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                                     ("ServiceManager");
            // Add services
            for (int i = 0; i < NumOfServices; i++)
            {
                TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                                        (i);
                if (i == FailedServiceSeqNumber)
                {
                    service.SetThrowExceptionOnStop(true);
                }
                serviceManager.AddTestService(service);
            }
            TestCompositeService.CompositeServiceImpl[] services = Collections.ToArray
                                                                       (serviceManager.GetServices(), new TestCompositeService.CompositeServiceImpl[0]);
            Configuration conf = new Configuration();

            // Initialise the composite service
            serviceManager.Init(conf);
            serviceManager.Start();
            // Stop the composite service
            try
            {
                serviceManager.Stop();
            }
            catch (TestCompositeService.ServiceTestRuntimeException)
            {
            }
            AssertInState(Service.STATE.Stopped, services);
        }
Ejemplo n.º 3
0
 public virtual void TestServiceLifecycleNoChildren()
 {
     TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                              ("ServiceManager");
     serviceManager.Init(new Configuration());
     serviceManager.Start();
     serviceManager.Stop();
 }
Ejemplo n.º 4
0
        public virtual void TestCallSequence()
        {
            TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                                     ("ServiceManager");
            // Add services
            for (int i = 0; i < NumOfServices; i++)
            {
                TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                                        (i);
                serviceManager.AddTestService(service);
            }
            TestCompositeService.CompositeServiceImpl[] services = Collections.ToArray
                                                                       (serviceManager.GetServices(), new TestCompositeService.CompositeServiceImpl[0]);
            Assert.Equal("Number of registered services ", NumOfServices,
                         services.Length);
            Configuration conf = new Configuration();

            // Initialise the composite service
            serviceManager.Init(conf);
            //verify they were all inited
            AssertInState(Service.STATE.Inited, services);
            // Verify the init() call sequence numbers for every service
            for (int i_1 = 0; i_1 < NumOfServices; i_1++)
            {
                Assert.Equal("For " + services[i_1] + " service, init() call sequence number should have been "
                             , i_1, services[i_1].GetCallSequenceNumber());
            }
            // Reset the call sequence numbers
            ResetServices(services);
            serviceManager.Start();
            //verify they were all started
            AssertInState(Service.STATE.Started, services);
            // Verify the start() call sequence numbers for every service
            for (int i_2 = 0; i_2 < NumOfServices; i_2++)
            {
                Assert.Equal("For " + services[i_2] + " service, start() call sequence number should have been "
                             , i_2, services[i_2].GetCallSequenceNumber());
            }
            ResetServices(services);
            serviceManager.Stop();
            //verify they were all stopped
            AssertInState(Service.STATE.Stopped, services);
            // Verify the stop() call sequence numbers for every service
            for (int i_3 = 0; i_3 < NumOfServices; i_3++)
            {
                Assert.Equal("For " + services[i_3] + " service, stop() call sequence number should have been "
                             , ((NumOfServices - 1) - i_3), services[i_3].GetCallSequenceNumber());
            }
            // Try to stop again. This should be a no-op.
            serviceManager.Stop();
            // Verify that stop() call sequence numbers for every service don't change.
            for (int i_4 = 0; i_4 < NumOfServices; i_4++)
            {
                Assert.Equal("For " + services[i_4] + " service, stop() call sequence number should have been "
                             , ((NumOfServices - 1) - i_4), services[i_4].GetCallSequenceNumber());
            }
        }
Ejemplo n.º 5
0
 public virtual void TestInitNullConf()
 {
     TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                              ("testInitNullConf");
     TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                             (0);
     serviceManager.AddTestService(service);
     try
     {
         serviceManager.Init(null);
         Log.Warn("Null Configurations are permitted " + serviceManager);
     }
     catch (ServiceStateException)
     {
     }
 }
Ejemplo n.º 6
0
 public virtual void TestServiceStopFromNotInited()
 {
     TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                              ("ServiceManager");
     // Add services
     for (int i = 0; i < NumOfServices; i++)
     {
         TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                                 (i);
         serviceManager.AddTestService(service);
     }
     TestCompositeService.CompositeServiceImpl[] services = Collections.ToArray
                                                                (serviceManager.GetServices(), new TestCompositeService.CompositeServiceImpl[0]);
     serviceManager.Stop();
     AssertInState(Service.STATE.Notinited, services);
 }
Ejemplo n.º 7
0
        public virtual void TestServiceStartup()
        {
            TestCompositeService.ServiceManager serviceManager = new TestCompositeService.ServiceManager
                                                                     ("ServiceManager");
            // Add services
            for (int i = 0; i < NumOfServices; i++)
            {
                TestCompositeService.CompositeServiceImpl service = new TestCompositeService.CompositeServiceImpl
                                                                        (i);
                if (i == FailedServiceSeqNumber)
                {
                    service.SetThrowExceptionOnStart(true);
                }
                serviceManager.AddTestService(service);
            }
            TestCompositeService.CompositeServiceImpl[] services = Collections.ToArray
                                                                       (serviceManager.GetServices(), new TestCompositeService.CompositeServiceImpl[0]);
            Configuration conf = new Configuration();

            // Initialise the composite service
            serviceManager.Init(conf);
            // Start the composite service
            try
            {
                serviceManager.Start();
                NUnit.Framework.Assert.Fail("Exception should have been thrown due to startup failure of last service"
                                            );
            }
            catch (TestCompositeService.ServiceTestRuntimeException)
            {
                for (int i_1 = 0; i_1 < NumOfServices - 1; i_1++)
                {
                    if (i_1 >= FailedServiceSeqNumber && StopOnlyStartedServices)
                    {
                        // Failed service state should be INITED
                        Assert.Equal("Service state should have been ", Service.STATE.
                                     Inited, services[NumOfServices - 1].GetServiceState());
                    }
                    else
                    {
                        Assert.Equal("Service state should have been ", Service.STATE.
                                     Stopped, services[i_1].GetServiceState());
                    }
                }
            }
        }