@Before public void before() throws Exception { distributionManager = mock(DistributionManager.class); persistenceService = mock(ConfigurationPersistenceService.class); service = spy(new LocatorClusterManagementService(distributionManager, persistenceService)); regionConfig = new RegionConfig(); }
@Before public void before() throws Exception { service = new JAXBService(CacheConfig.class); regionConfig = new RegionConfig(); xmlResource = RegionConfigTest.class.getResource("RegionConfigTest.xml"); assertThat(xmlResource).isNotNull(); master = service.unMarshall(FileUtils.readFileToString(new File(xmlResource.getFile()), "UTF-8")); }
@Before public void before() throws Exception { validator = new RegionConfigValidator(); config = new RegionConfig(); }
@Test public void getValidRegionName() { CacheConfig cacheConfig = mock(CacheConfig.class); RegionConfig region = new RegionConfig("regionA.regionB", "REPLICATE"); when(cacheConfig.findRegionConfiguration("/regionA.regionB")).thenReturn(region); assertThat(command.getValidRegionName("regionB", cacheConfig)).isEqualTo("regionB"); assertThat(command.getValidRegionName("/regionB", cacheConfig)).isEqualTo("/regionB"); assertThat(command.getValidRegionName("/regionB b", cacheConfig)).isEqualTo("/regionB"); assertThat(command.getValidRegionName("/regionB.entrySet()", cacheConfig)) .isEqualTo("/regionB"); assertThat(command.getValidRegionName("/regionA.regionB.entrySet() A", cacheConfig)) .isEqualTo("/regionA.regionB"); assertThat(command.getValidRegionName("/regionB.regionA.entrySet() B", cacheConfig)) .isEqualTo("/regionB"); } }
@Test public void createsPartitionedInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); config.setType("PARTITION"); RegionConfigRealizer realizer = new RegionConfigRealizer(); realizer.create(config, cache); ArgumentCaptor<DataPolicy> dataPolicyArgumentCaptor = ArgumentCaptor.forClass(DataPolicy.class); verify(regionFactory).setDataPolicy(dataPolicyArgumentCaptor.capture()); assertThat(dataPolicyArgumentCaptor.getValue()).isEqualTo(DataPolicy.PARTITION); verify(regionFactory).create("regionName"); }
@Test public void createsReplicateInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); config.setType("REPLICATE"); RegionConfigRealizer subject = new RegionConfigRealizer(); subject.create(config, cache); ArgumentCaptor<DataPolicy> dataPolicyArgumentCaptor = ArgumentCaptor.forClass(DataPolicy.class); verify(regionFactory).setDataPolicy(dataPolicyArgumentCaptor.capture()); assertThat(dataPolicyArgumentCaptor.getValue()).isEqualTo(DataPolicy.REPLICATE); verify(regionFactory).create("regionName"); } }
@Before public void setUp() throws Exception { function = spy(RegionAlterFunction.class); config = new RegionConfig(); regionAttributes = new RegionAttributesType(); config.setRegionAttributes(regionAttributes); internalCache = mock(InternalCache.class); cache = mock(InternalCacheForClientAccess.class); mutator = mock(AttributesMutator.class); evictionMutator = mock(EvictionAttributesMutator.class); when(mutator.getEvictionAttributesMutator()).thenReturn(evictionMutator); region = mock(AbstractRegion.class); context = mock(FunctionContext.class); when(context.getCache()).thenReturn(internalCache); when(internalCache.getCacheForProcessingClientRequests()).thenReturn(cache); when(context.getArguments()).thenReturn(config); when(context.getMemberName()).thenReturn("member"); when(cache.getRegion(any())).thenReturn(region); when(region.getAttributesMutator()).thenReturn(mutator); }
@Before public void before() { command = spy(AlterRegionCommand.class); cache = mock(InternalCache.class); command.setCache(cache); when(cache.getSecurityService()).thenReturn(mock(SecurityService.class)); ccService = mock(InternalConfigurationPersistenceService.class); doReturn(ccService).when(command).getConfigurationPersistenceService(); Set<DistributedMember> members = Stream.of(mock(DistributedMember.class)).collect(Collectors.toSet()); doReturn(members).when(command).findMembers(any(), any()); CliFunctionResult result = new CliFunctionResult("member", CliFunctionResult.StatusState.OK, "regionA altered"); doReturn(Arrays.asList(result)).when(command).executeAndGetFunctionResult(any(), any(), any()); cacheConfig = new CacheConfig(); existingRegionConfig = new RegionConfig(); existingRegionConfig.setName("/regionA"); existingRegionConfig.setType("REPLICATE"); cacheConfig.getRegions().add(existingRegionConfig); when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig); }
@Test public void subRegionsUnsupported() { regionConfig = new RegionConfig(); assertThatThrownBy(() -> regionConfig.setName("/Parent/Child")) .isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> regionConfig.setName("Parent/Child")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void updateRegionConfig() { service.updateCacheConfig("cluster", cacheConfig -> { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("regionA"); regionConfig.setType("REPLICATE"); cacheConfig.getRegions().add(regionConfig); return cacheConfig; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()) .contains("<region name=\"regionA\" refid=\"REPLICATE\">"); }
@Test public void checkDefaultRegionAttributesForShortcuts() { RegionShortcut[] shortcuts = RegionShortcut.values(); for (RegionShortcut shortcut : shortcuts) { RegionConfig config = new RegionConfig(); config.setType(shortcut.name()); config.setName(shortcut.name()); RegionConfig masterRegion = CacheElement.findElement(master.getRegions(), shortcut.name()); assertThat(config).isEqualToComparingFieldByFieldRecursively(masterRegion); } }
@Test public void regionConfig() { cacheConfig = new CacheConfig("1.0"); RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("test"); regionConfig.setType("REPLICATE"); RegionAttributesType attributes = new RegionAttributesType(); attributes.setCacheLoader(new DeclarableType("abc.Foo")); regionConfig.setRegionAttributes(attributes); cacheConfig.getRegions().add(regionConfig); // make sure the xml marshed by this config can be validated with xsd String xml = service.marshall(cacheConfig); CacheConfig newCache = service.unMarshall(xml); assertThat(cacheConfig).isEqualToComparingFieldByFieldRecursively(newCache); }
public static void setBasicValues(CacheConfig cache) { cache.setCopyOnRead(true); CacheConfig.GatewayReceiver receiver = new CacheConfig.GatewayReceiver(); receiver.setBindAddress("localhost"); receiver.setEndPort("8080"); receiver.setManualStart(false); receiver.setStartPort("6000"); cache.setGatewayReceiver(receiver); cache.setVersion("1.0"); RegionConfig region = new RegionConfig(); region.setName("testRegion"); region.setType("REPLICATE"); cache.getRegions().add(region); }
@Before public void setUp() throws Exception { cacheConfig = new CacheConfig("1.0"); cacheXml = "<cache version=\"1.0\" xsi:schemaLocation=\"http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd\" xmlns=\"http://geode.apache.org/schema/cache\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"; service = new JAXBService(CacheConfig.class); service.validateWithLocalCacheXSD(); regionConfig = new RegionConfig(); regionConfig.setName("regionA"); regionConfig.setType("REPLICATE"); regionXml = "<region name=\"regionA\" refid=\"REPLICATE\">"; classNameTypeXml = "<class-name>my.className</class-name>"; declarableWithString = new DeclarableType("my.className", "{'key':'value'}"); declarableWithStringXml = classNameTypeXml + "<parameter name=\"key\"><string>value</string></parameter>"; declarableWithParam = new DeclarableType("my.className"); ParameterType param = new ParameterType("key"); param.setDeclarable(declarableWithString); declarableWithParam.getParameters().add(param); declarableWithParamXml = classNameTypeXml + "<parameter name=\"key\"><declarable>" + declarableWithStringXml + "</declarable></parameter>"; }
RegionConfig deltaConfig = new RegionConfig(); deltaConfig.setName(regionPath); RegionAttributesType regionAttributesType = new RegionAttributesType();