private List<DeclarableType> stringsToDeclarableTypes(String[] objects) { return Arrays.stream(objects).map(fullyQualifiedClassName -> { DeclarableType thisFilter = new DeclarableType(); thisFilter.setClassName(fullyQualifiedClassName); return thisFilter; }).collect(Collectors.toList()); }
private void setCacheWriter(RegionAttributesType attributes) { DeclarableType writer = new DeclarableType(); writer.setClassName(JdbcWriter.class.getName()); attributes.setCacheWriter(writer); } }
private void setCacheLoader(RegionAttributesType attributes) { DeclarableType loader = new DeclarableType(); loader.setClassName(JdbcLoader.class.getName()); attributes.setCacheLoader(loader); }
@Test public void emptyDeclarable() { assertThat(new DeclarableType("")) .isEqualTo(new DeclarableType("", (Properties) null)) .isEqualTo(new DeclarableType("", "")) .isEqualTo(new DeclarableType("", "{}")) .isEqualTo(new DeclarableType(" ", "{}")) .isEqualTo(new DeclarableType(null, "{}")) .isEqualTo(DeclarableType.EMPTY); } }
public ExpirationAttributesType(Integer timeout, ExpirationAction action, String expiry, Properties iniProps) { expirationAttributes.setTimeout(Objects.toString(timeout, null)); if (action != null) { expirationAttributes.setAction(action.toXmlString()); } if (expiry != null) { expirationAttributes.setCustomExpiry(new DeclarableType(expiry, iniProps)); } }
@Test public void createDeclarableInstanceFromDeclarableType() { DeclarableType declarableType = new DeclarableType(MyDeclarable.class.getName(), "{\"value1\":5,\"value2\":\"some string\"}"); MyDeclarable result = DeclarableTypeInstantiator.newInstance(declarableType, cache); assertThat(result).isNotNull().isInstanceOf(MyDeclarable.class); assertThat(result.props).isNotNull(); assertThat(result.props.getProperty("value1")).isEqualTo("5"); assertThat(result.props.getProperty("value2")).isEqualTo("some string"); }
@Test public void createDeclarableInstancedFromNestedDeclarableType() { DeclarableType declarableType = new DeclarableType(MyDeclarable.class.getName(), "{\"value1\":5,\"value2\":\"some string\"}"); ParameterType parameterType = new ParameterType("inner-prop", declarableType); DeclarableType outerDeclarable = new DeclarableType(MyOuterDeclarable.class.getName()); outerDeclarable.getParameters().add(parameterType); MyOuterDeclarable result = DeclarableTypeInstantiator.newInstance(outerDeclarable, cache); assertThat(result.props).isNotNull(); MyDeclarable innerDeclarable = (MyDeclarable) result.props.get("inner-prop"); assertThat(innerDeclarable.props.getProperty("value1")).isEqualTo("5"); assertThat(innerDeclarable.props.getProperty("value2")).isEqualTo("some string"); } }
private CacheConfig.GatewayReceiver buildConfiguration(Boolean manualStart, Integer startPort, Integer endPort, String bindAddress, Integer maximumTimeBetweenPings, Integer socketBufferSize, String[] gatewayTransportFilters, String hostnameForSenders) { CacheConfig.GatewayReceiver configuration = new CacheConfig.GatewayReceiver(); if (gatewayTransportFilters != null) { List<DeclarableType> filters = Arrays.stream(gatewayTransportFilters).map(fullyQualifiedClassName -> { DeclarableType thisFilter = new DeclarableType(); thisFilter.setClassName(fullyQualifiedClassName); return thisFilter; }).collect(Collectors.toList()); configuration.getGatewayTransportFilters().addAll(filters); } if (startPort != null) { configuration.setStartPort(String.valueOf(startPort)); } if (endPort != null) { configuration.setEndPort(String.valueOf(endPort)); } configuration.setBindAddress(bindAddress); if (maximumTimeBetweenPings != null) { configuration.setMaximumTimeBetweenPings(String.valueOf(maximumTimeBetweenPings)); } if (socketBufferSize != null) { configuration.setSocketBufferSize(String.valueOf(socketBufferSize)); } configuration.setHostnameForSenders(hostnameForSenders); configuration.setManualStart(manualStart); return configuration; }
default RegionAttributesType.PartitionAttributes convertToConfigPartitionAttributes() { RegionAttributesType.PartitionAttributes configAttributes = new RegionAttributesType.PartitionAttributes(); configAttributes.setColocatedWith(getColocatedWith()); configAttributes.setLocalMaxMemory(Integer.toString(getLocalMaxMemory())); if (getPartitionResolver() != null) { configAttributes .setPartitionResolver(new DeclarableType(getPartitionResolver().getClass().getName())); } configAttributes.setRecoveryDelay(Long.toString(getRecoveryDelay())); configAttributes.setStartupRecoveryDelay(Long.toString(getStartupRecoveryDelay())); configAttributes.setRedundantCopies(Integer.toString(getRedundantCopies())); configAttributes.setTotalMaxMemory(Long.toString(getTotalMaxMemory())); configAttributes.setTotalNumBuckets(Long.toString(getTotalNumBuckets())); return configAttributes; } }
@Test public void declarableWithDeclarableParam() { DeclarableType declarable = new DeclarableType("className"); ParameterType param = new ParameterType("param1"); param.setDeclarable(new DeclarableType("anotherClassName", "{'k':'v'}")); declarable.getParameters().add(param); assertThat(declarable.toString()).isEqualTo("className{param1:anotherClassName{k:v}}"); DeclarableType d2 = new DeclarableType("className"); ParameterType p2 = new ParameterType("param1"); p2.setDeclarable(new DeclarableType("anotherClassName", "{'k':'v'}")); d2.getParameters().add(p2); assertThat(declarable).isEqualTo(d2); DeclarableType d3 = new DeclarableType("className"); ParameterType p3 = new ParameterType("param1"); p3.setDeclarable(new DeclarableType("anotherClassName", "{'k':'v2'}")); d3.getParameters().add(p3); assertThat(declarable).isNotEqualTo(d3); }
public static RegionAttributesType.ExpirationAttributesType getExpirationAttributes( Integer timeout, ExpirationAction action, ClassName<CustomExpiry> expiry) { if (timeout == null && action == null && expiry == null) { return null; } RegionAttributesType.ExpirationAttributesType attributesType = new RegionAttributesType.ExpirationAttributesType(); attributesType.setTimeout(Objects.toString(timeout, "0")); if (action == null) { action = ExpirationAction.INVALIDATE; } attributesType.setAction(action.toXmlString()); if (expiry != null) { attributesType.setCustomExpiry(new DeclarableType(expiry.getClassName())); } return attributesType; }
@Test public void declarableWithStringParam() { DeclarableType declarable = new DeclarableType("className"); assertThat(declarable).isEqualTo(declarable); assertThat(declarable).isEqualTo(new DeclarableType("className")); assertThat(declarable).isNotEqualTo(new DeclarableType("anotherClassName")); ParameterType parameter = new ParameterType("name", "value"); declarable.getParameters().add(parameter); DeclarableType d2 = new DeclarableType("className"); assertThat(declarable).isNotEqualTo(d2); d2.getParameters().add(parameter); assertThat(declarable).isEqualTo(d2); // has one common parameter, but d2 has additional param d2.getParameters().add(new ParameterType("name1", "value1")); assertThat(declarable).isNotEqualTo(d2); // same size, but different param value DeclarableType d3 = new DeclarableType("className"); d3.getParameters().add(new ParameterType("name", "value1")); assertThat(declarable).isNotEqualTo(d3); assertThat(declarable.toString()).isEqualTo("className{name:value}"); }
private void createAsyncQueue(CacheConfig cacheConfig, RegionAttributesType attributes, String queueName) { AsyncEventQueue asyncEventQueue = new AsyncEventQueue(); asyncEventQueue.setId(queueName); boolean isPartitioned = attributes.getDataPolicy().equals(RegionAttributesDataPolicy.PARTITION) || attributes.getDataPolicy().equals(RegionAttributesDataPolicy.PERSISTENT_PARTITION); asyncEventQueue.setParallel(isPartitioned); DeclarableType listener = new DeclarableType(); listener.setClassName(JdbcAsyncWriter.class.getName()); asyncEventQueue.setAsyncEventListener(listener); cacheConfig.getAsyncEventQueues().add(asyncEventQueue); }
@Test public void alterWithCacheListener() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-listener=abc,def"); List<DeclarableType> cacheListeners = deltaConfig.getRegionAttributes().getCacheListeners(); assertThat(cacheListeners).hasSize(2); assertThat(cacheListeners.get(0).getClassName()).isEqualTo("abc"); assertThat(cacheListeners.get(1).getClassName()).isEqualTo("def"); // check that the combined the configuration is created as expected RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.getCacheListeners().add(new DeclarableType("ghi")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); List<DeclarableType> updatedCacheListeners = existingRegionConfig.getRegionAttributes().getCacheListeners(); assertThat(updatedCacheListeners).hasSize(2); assertThat(updatedCacheListeners.get(0).getClassName()).isEqualTo("abc"); assertThat(updatedCacheListeners.get(1).getClassName()).isEqualTo("def"); assertThat(existingRegionConfig.getRegionAttributes().getEntryIdleTime()).isNull(); }
@Test public void alterWithNoCacheListener() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-listener=''"); List<DeclarableType> cacheListeners = deltaConfig.getRegionAttributes().getCacheListeners(); assertThat(cacheListeners).hasSize(1); assertThat(cacheListeners.get(0)).isEqualTo(DeclarableType.EMPTY); RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.getCacheListeners().add(new DeclarableType("ghi")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); List<DeclarableType> updatedCacheListeners = existingRegionConfig.getRegionAttributes().getCacheListeners(); assertThat(updatedCacheListeners).hasSize(0); }
@Test public void alterWithCacheLoader() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-loader=abc"); RegionAttributesType deltaAttributes = deltaConfig.getRegionAttributes(); assertThat(deltaAttributes.getCacheWriter()).isNull(); assertThat(deltaAttributes.getCacheLoader().getClassName()).isEqualTo("abc"); assertThat(deltaAttributes.getCacheListeners()).isNotNull().isEmpty(); RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.getCacheListeners().add(new DeclarableType("def")); existingAttributes.setCacheLoader(new DeclarableType("def")); existingAttributes.setCacheWriter(new DeclarableType("def")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); // after update, the cache listeners remains the same assertThat(existingAttributes.getCacheListeners()).hasSize(1); assertThat(existingAttributes.getCacheListeners().get(0).getClassName()).isEqualTo("def"); // after update the cache writer remains the same assertThat(existingAttributes.getCacheWriter().getClassName()).isEqualTo("def"); // after update the cache loader is changed assertThat(existingAttributes.getCacheLoader().getClassName()).isEqualTo("abc"); }
@Test public void alterWithNoCacheLoader() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --cache-loader=''"); RegionAttributesType deltaAttributes = deltaConfig.getRegionAttributes(); assertThat(deltaAttributes.getCacheLoader()).isEqualTo(DeclarableType.EMPTY); RegionAttributesType existingAttributes = new RegionAttributesType(); existingAttributes.setCacheLoader(new DeclarableType("def")); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); // after the update the cache loader is null assertThat(existingAttributes.getCacheLoader()).isNull(); }
@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>"; }
pdxType.setPdxSerializer(new DeclarableType(ReflectionBasedAutoSerializer.class.getName(), autoSerializer.getConfig()));
@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); }