/** * Verify that the single port feature is enabled. Initializes features if the provided one is null, allowing for * lazily initialized Features instance. * @param features existing instance or null * @return the features instance that was checked, always non null * @throws StartException thrown if the single port feature was disabled */ private Features checkSinglePortEnabled(Features features) throws StartException { if (features == null) { features = new Features(getClass().getClassLoader()); } if (!features.isAvailable(SINGLE_PORT_FEATURE)) { throw LogFactory.getLog(MethodHandles.lookup().lookupClass()).featureDisabled(SINGLE_PORT_FEATURE); } return features; }
@Test public void testNotAvailableFeature() { Features features = mock(Features.class); dataContainerFactory.globalConfiguration = mock(GlobalConfiguration.class); when(dataContainerFactory.globalConfiguration.features()).thenReturn(features); when(features.isAvailable(DataContainerFactory.SEGMENTATION_FEATURE)).thenReturn(false); dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().storageType(StorageType.OFF_HEAP).evictionStrategy(EvictionStrategy.REMOVE).size(1000) .clustering().cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(BoundedOffHeapDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); } }
@Test public void testSegmentedOffHeap() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_ASYNC) .memory().storageType(StorageType.OFF_HEAP).build(); assertTrue(dataContainerFactory.globalConfiguration.features().isAvailable(DataContainerFactory.SEGMENTATION_FEATURE)); assertEquals(DefaultSegmentedDataContainer.class, dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test public void testFeatures() { Features features = new Features(); assertFalse(features.isAvailable("A")); assertTrue(features.isAvailable("B")); }
@Test public void featureSysOverride() { Features features = new Features(); assertFalse(features.isAvailable("A")); System.setProperty("org.infinispan.feature.A", "true"); System.setProperty("org.infinispan.feature.B", "false"); boolean a = features.isAvailable("A"); boolean b = features.isAvailable("B"); System.clearProperty("org.infinispan.feature.A"); System.clearProperty("org.infinispan.feature.B"); assertTrue(a); assertFalse(b); } }