private static Region<?, ?> createPartitionedRegion(String regionName, Cache cache, Class keyConstraint, Class valueConstraint) { RegionFactory regionFactory = cache.createRegionFactory(); regionFactory.setDataPolicy(DataPolicy.PARTITION); regionFactory.setKeyConstraint(keyConstraint); regionFactory.setValueConstraint(valueConstraint); return regionFactory.create(regionName); }
@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"); } }
@SuppressWarnings("unchecked") private LocalRegion createOrRetrieveGatewayDeltaRegion() { Region region = this.cache.getRegion(GatewayDelta.GATEWAY_DELTA_REGION_NAME); if (region == null) { region = new RegionFactory().setScope(Scope.LOCAL).setDataPolicy(DataPolicy.EMPTY) .setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)) // TODO: Disabled for WAN // .setEnableGateway(true) .addCacheListener(new GatewayDeltaEventApplicationCacheListener()) .create(GatewayDelta.GATEWAY_DELTA_REGION_NAME); } if (this.cache.getLogger().fineEnabled()) { StringBuilder builder = new StringBuilder(); builder.append("GatewayDeltaForwarderCacheListener: Created gateway delta region: ") .append(region); this.cache.getLogger().fine(builder.toString()); } return (LocalRegion) region; }
private RegionFactory getRegionFactory(Cache cache, RegionAttributesType regionAttributes) { RegionFactory factory = cache.createRegionFactory(); factory.setDataPolicy(DataPolicy.fromString(regionAttributes.getDataPolicy().name()));
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null) { dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_PARTITION : DataPolicy.PARTITION); } else { // Validate that the user-defined Data Policy matches the appropriate Spring GemFire XML namespace // configuration meta-data element for Region (i.e. <gfe:partitioned-region .../>)! Assert.isTrue(dataPolicy.withPartitioning(), String.format( "Data Policy '%1$s' is not supported in Partitioned Regions.", dataPolicy)); } // Validate the data-policy and persistent attributes are compatible when specified! RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); }
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null) { dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE); } else if (DataPolicy.EMPTY.equals(dataPolicy)) { dataPolicy = DataPolicy.EMPTY; } else { // Validate that the user-defined Data Policy matches the appropriate Spring GemFire XML namespace // configuration meta-data element for the Region (i.e. <gfe:replicated-region .../>)! Assert.isTrue(dataPolicy.withReplication(), String.format( "Data Policy '%1$s' is not supported in Replicated Regions.", dataPolicy)); } // Validate that the data-policy and persistent attributes are compatible when both are specified! RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); }
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null || DataPolicy.NORMAL.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped NORMAL Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.NORMAL); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PRELOADED.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped PRELOADED Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.PRELOADED); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy) && RegionShortcutWrapper.valueOf(getShortcut()).isPersistent()) { regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); } else { throw new IllegalArgumentException(String.format("Data Policy '%1$s' is not supported for Local Regions.", dataPolicy)); } }
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null || DataPolicy.NORMAL.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped NORMAL Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.NORMAL); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PRELOADED.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped PRELOADED Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.PRELOADED); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy) && RegionShortcutWrapper.valueOf(getShortcut()).isPersistent()) { regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); } else { throw new IllegalArgumentException(String.format("Data Policy '%1$s' is not supported for Local Regions.", dataPolicy)); } }
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null) { dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE); } else if (DataPolicy.EMPTY.equals(dataPolicy)) { dataPolicy = DataPolicy.EMPTY; } else { // Validate that the user-defined Data Policy matches the appropriate Spring Pivotal GemFire XML namespace // configuration meta-data element for the Region (i.e. <gfe:replicated-region .../>)! Assert.isTrue(dataPolicy.withReplication(), String.format( "Data Policy '%1$s' is not supported in Replicated Regions.", dataPolicy)); } // Validate that the data-policy and persistent attributes are compatible when both are specified! RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); }
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null) { dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_PARTITION : DataPolicy.PARTITION); } else { // Validate that the user-defined Data Policy matches the appropriate Spring Pivotal GemFire XML namespace // configuration meta-data element for Region (i.e. <gfe:partitioned-region .../>)! Assert.isTrue(dataPolicy.withPartitioning(), String.format( "Data Policy '%1$s' is not supported in Partitioned Regions.", dataPolicy)); } // Validate the data-policy and persistent attributes are compatible when specified! RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); }
/** * Validates and sets the {@link DataPolicy} on the {@link RegionFactory} used to create and configure * the {@link Region} from this {@link FactoryBean}. * * @param regionFactory the RegionFactory used by this FactoryBean to create and configure the Region. * @param persistent a boolean value indicating whether the Region should be persistent and persist it's * data to disk. * @param dataPolicy the configured Data Policy for the Region. * @see #resolveDataPolicy(org.apache.geode.cache.RegionFactory, Boolean, String) * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.RegionFactory */ protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy != null) { RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, this.persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); } else { resolveDataPolicy(regionFactory, persistent, (String) null); } }
/** * Validates and sets the Data Policy on the RegionFactory used to create and configure the Region from this * FactoryBean. * * @param regionFactory the RegionFactory used by this FactoryBean to create and configure the Region. * @param persistent a boolean value indicating whether the Region should be persistent and persist it's * data to disk. * @param dataPolicy the configured Data Policy for the Region. * @see #resolveDataPolicy(org.apache.geode.cache.RegionFactory, Boolean, String) * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.RegionFactory */ protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy != null) { RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, this.persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); } else { resolveDataPolicy(regionFactory, persistent, (String) null); } }
/** * Validates the configured Data Policy and may override it, taking into account the 'persistent' attribute * and constraints for the Region type. * * @param regionFactory the GemFire RegionFactory used to create the desired Region. * @param persistent a boolean value indicating whether the Region should persist it's data to disk. * @param dataPolicy requested Data Policy as set by the user in the Spring GemFire configuration meta-data. * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.RegionFactory */ protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) { if (dataPolicy != null) { DataPolicy resolvedDataPolicy = new DataPolicyConverter().convert(dataPolicy); Assert.notNull(resolvedDataPolicy, String.format("Data Policy [%s] is invalid", dataPolicy)); RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(resolvedDataPolicy, this.persistent); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else { DataPolicy regionAttributesDataPolicy = getDataPolicy(getAttributes(), DataPolicy.DEFAULT); DataPolicy resolvedDataPolicy = isPersistent() && DataPolicy.DEFAULT.equals(regionAttributesDataPolicy) ? DataPolicy.PERSISTENT_REPLICATE : regionAttributesDataPolicy; RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(resolvedDataPolicy, this.persistent); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } }
/** * Validates the configured Data Policy and may override it, taking into account the 'persistent' attribute * and constraints for the Region type. * * @param regionFactory the Pivotal GemFire RegionFactory used to create the desired Region. * @param persistent a boolean value indicating whether the Region should persist it's data to disk. * @param dataPolicy requested Data Policy as set by the user in the Spring Pivotal GemFire configuration meta-data. * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.RegionFactory */ protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) { if (dataPolicy != null) { DataPolicy resolvedDataPolicy = new DataPolicyConverter().convert(dataPolicy); Assert.notNull(resolvedDataPolicy, String.format("Data Policy [%s] is invalid", dataPolicy)); RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(resolvedDataPolicy, this.persistent); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } else { DataPolicy regionAttributesDataPolicy = getDataPolicy(getAttributes(), DataPolicy.DEFAULT); DataPolicy resolvedDataPolicy = isPersistent() && DataPolicy.DEFAULT.equals(regionAttributesDataPolicy) ? DataPolicy.PERSISTENT_REPLICATE : regionAttributesDataPolicy; RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(resolvedDataPolicy, this.persistent); regionFactory.setDataPolicy(resolvedDataPolicy); setDataPolicy(resolvedDataPolicy); } }
@SuppressWarnings("unchecked") private LocalRegion createOrRetrieveGatewayDeltaRegion() { Region region = this.cache.getRegion(GatewayDelta.GATEWAY_DELTA_REGION_NAME); if (region == null) { region = new RegionFactory().setScope(Scope.LOCAL).setDataPolicy(DataPolicy.EMPTY) .setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)) // TODO: Disabled for WAN // .setEnableGateway(true) .addCacheListener(new GatewayDeltaEventApplicationCacheListener()) .create(GatewayDelta.GATEWAY_DELTA_REGION_NAME); } if (this.cache.getLogger().fineEnabled()) { StringBuilder builder = new StringBuilder(); builder.append("GatewayDeltaForwarderCacheListener: Created gateway delta region: ") .append(region); this.cache.getLogger().fine(builder.toString()); } return (LocalRegion) region; }
.thenAnswer(newSetter(customEntryTimeToLive, mockRegionFactory)); when(mockRegionFactory.setDataPolicy(any(DataPolicy.class))) .thenAnswer(newSetter(dataPolicy, mockRegionFactory));