Search in sources :

Example 16 with HazelcastInternalOSGiService

use of com.hazelcast.osgi.impl.HazelcastInternalOSGiService in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method groupNameIsSetToDefaultGroupNameOfBundleWhenConfigIsGivenWithNullGroupConfigAndGroupingIsNotDisabled.

@Test
public void groupNameIsSetToDefaultGroupNameOfBundleWhenConfigIsGivenWithNullGroupConfigAndGroupingIsNotDisabled() {
    Config config = new Config();
    config.setGroupConfig(null);
    HazelcastInternalOSGiService service = getService();
    HazelcastOSGiInstance osgiInstance = service.newHazelcastInstance(config);
    assertEquals(HazelcastInternalOSGiService.DEFAULT_GROUP_NAME, osgiInstance.getConfig().getGroupConfig().getName());
    HazelcastInstance instance = osgiInstance.getDelegatedInstance();
    assertEquals(HazelcastInternalOSGiService.DEFAULT_GROUP_NAME, instance.getConfig().getGroupConfig().getName());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 17 with HazelcastInternalOSGiService

use of com.hazelcast.osgi.impl.HazelcastInternalOSGiService in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method instanceShutdownSuccessfullyAlthoughThereIsExceptionWhileDeregister.

@Test
public void instanceShutdownSuccessfullyAlthoughThereIsExceptionWhileDeregister() {
    final String INSTANCE_NAME = "test-osgi-instance";
    registerDeregisterListener.throwExceptionOnDeregister = true;
    HazelcastInternalOSGiService service = getService();
    Config config = new Config(INSTANCE_NAME);
    HazelcastOSGiInstance osgiInstance = service.newHazelcastInstance(config);
    assertTrue(osgiInstance.getLifecycleService().isRunning());
    HazelcastInstance instance = osgiInstance.getDelegatedInstance();
    assertTrue(instance.getLifecycleService().isRunning());
    service.shutdownHazelcastInstance(osgiInstance);
    assertFalse(osgiInstance.getLifecycleService().isRunning());
    assertFalse(instance.getLifecycleService().isRunning());
    assertNull(service.getHazelcastInstanceByName(INSTANCE_NAME));
    assertFalse(service.getAllHazelcastInstances().contains(osgiInstance));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 18 with HazelcastInternalOSGiService

use of com.hazelcast.osgi.impl.HazelcastInternalOSGiService in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method instanceRetrievedSuccessfullyWithItsName.

@Test
public void instanceRetrievedSuccessfullyWithItsName() {
    final String INSTANCE_NAME = "test-osgi-instance";
    HazelcastInternalOSGiService service = getService();
    Config config = new Config(INSTANCE_NAME);
    service.newHazelcastInstance(config);
    HazelcastOSGiInstance osgiInstance = service.getHazelcastInstanceByName(INSTANCE_NAME);
    assertNotNull(osgiInstance);
    assertEquals(config, osgiInstance.getConfig());
    HazelcastInstance instance = osgiInstance.getDelegatedInstance();
    assertNotNull(instance);
    assertEquals(config, instance.getConfig());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 19 with HazelcastInternalOSGiService

use of com.hazelcast.osgi.impl.HazelcastInternalOSGiService in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method groupNameIsSetToSpecifiedGroupNameWhenGroupingIsDisabled.

@Test
public void groupNameIsSetToSpecifiedGroupNameWhenGroupingIsDisabled() throws BundleException {
    final String GROUP_NAME = "my-osgi-group";
    String propValue = System.getProperty(HazelcastOSGiService.HAZELCAST_OSGI_GROUPING_DISABLED);
    TestBundle testBundle = null;
    try {
        System.setProperty(HazelcastOSGiService.HAZELCAST_OSGI_GROUPING_DISABLED, "true");
        testBundle = new TestBundle();
        TestBundleContext testBundleContext = testBundle.getBundleContext();
        testBundle.start();
        HazelcastInternalOSGiService service = getService(testBundleContext);
        assertNotNull(service);
        Config config = new Config();
        config.getGroupConfig().setName(GROUP_NAME);
        HazelcastOSGiInstance osgiInstance = service.newHazelcastInstance(config);
        assertEquals(GROUP_NAME, osgiInstance.getConfig().getGroupConfig().getName());
        HazelcastInstance instance = osgiInstance.getDelegatedInstance();
        assertEquals(GROUP_NAME, instance.getConfig().getGroupConfig().getName());
    } finally {
        if (propValue != null) {
            System.setProperty(HazelcastOSGiService.HAZELCAST_OSGI_GROUPING_DISABLED, propValue);
        }
        if (testBundle != null) {
            testBundle.stop();
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 20 with HazelcastInternalOSGiService

use of com.hazelcast.osgi.impl.HazelcastInternalOSGiService in project hazelcast by hazelcast.

the class HazelcastOSGiServiceTest method serviceIsNotOperationalWhenItIsNotActive.

@Test
public void serviceIsNotOperationalWhenItIsNotActive() throws BundleException {
    TestBundle testBundle = null;
    try {
        testBundle = new TestBundle();
        TestBundleContext testBundleContext = testBundle.getBundleContext();
        testBundle.start();
        HazelcastInternalOSGiService service = getService(testBundleContext);
        assertNotNull(service);
        testBundle.stop();
        testBundle = null;
        try {
            service.newHazelcastInstance();
            fail("OSGI service is not active so it is not in operation mode." + " It is expected to get `IllegalStateException` here!");
        } catch (IllegalStateException e) {
        // since the bundle is not active, it is expected to get `IllegalStateException`
        }
    } finally {
        if (testBundle != null) {
            testBundle.stop();
        }
    }
}
Also used : HazelcastInternalOSGiService(com.hazelcast.osgi.impl.HazelcastInternalOSGiService) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

HazelcastInternalOSGiService (com.hazelcast.osgi.impl.HazelcastInternalOSGiService)23 SlowTest (com.hazelcast.test.annotation.SlowTest)23 Test (org.junit.Test)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Config (com.hazelcast.config.Config)11 GroupConfig (com.hazelcast.config.GroupConfig)11 HashSet (java.util.HashSet)3