/** * This method creates a partitioned region with all the default values. The cache created is a * loner, so this is only suitable for single VM tests. * */ public static Region createPartionedRegion(String regionname) throws RegionExistsException { return createPartionedRegion(regionname, new PartitionAttributesFactory().create()); }
/** * convenience method to create a partition region with customized regionFactory and a customized * PartitionAttributeFactory * * @param regionFactoryConsumer a lamda that allows you to customize the regionFactory * @param attributesFactoryConsumer a lamda that allows you to customize the * partitionAttributeFactory */ public Region createPartitionRegion(String name, Consumer<RegionFactory> regionFactoryConsumer, Consumer<PartitionAttributesFactory> attributesFactoryConsumer) { return createRegion(RegionShortcut.PARTITION, name, rf -> { regionFactoryConsumer.accept(rf); PartitionAttributesFactory attributeFactory = new PartitionAttributesFactory(); attributesFactoryConsumer.accept(attributeFactory); rf.setPartitionAttributes(attributeFactory.create()); }); }
private PartitionedRegion mockPR(String name) { PartitionedRegion region = mock(PartitionedRegion.class); when(region.getFullPath()).thenReturn(name); when(region.getPartitionAttributes()).thenReturn(new PartitionAttributesFactory<>().create()); when(region.getTotalNumberOfBuckets()).thenReturn(113); when(region.getDataPolicy()).thenReturn(DataPolicy.PARTITION); return region; }
public void createPartitionRegion(String name, Class constraint) { ExpirationAttributes expiration = ExpirationAttributes.DEFAULT; PartitionAttributesFactory paf = new PartitionAttributesFactory(); RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(paf.create()); if (constraint != null) { factory.setValueConstraint(constraint); } factory.create(name); }
@Override public Object call() throws Exception { PartitionAttributesFactory paf = new PartitionAttributesFactory(); RegionFactory factory = getCache().createRegionFactory(RegionShortcut.PARTITION) .setPartitionAttributes(paf.create()); if (valueConstraint != null) { factory.setValueConstraint(valueConstraint); } factory.create(regionName); return true; } });
private Region initializeScenario(final boolean withPersistence, final String regionPath, final Cache cache, int localMaxMemory) { PartitionedRegion region = mock(PartitionedRegion.class); PartitionAttributes partitionAttributes = new PartitionAttributesFactory() .setLocalMaxMemory(localMaxMemory).setTotalNumBuckets(103).create(); RegionAttributes regionAttributes = spy(createRegionAttributes(withPersistence, partitionAttributes)); ExtensionPoint extensionPoint = mock(ExtensionPoint.class); when(cache.getRegion(regionPath)).thenReturn(region); when(cache.getRegionAttributes(any())).thenReturn(regionAttributes); when(region.getAttributes()).thenReturn(regionAttributes); when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes); when(region.getPartitionAttributes()).thenReturn(partitionAttributes); when(region.getExtensionPoint()).thenReturn(extensionPoint); return region; }
public void setDataPolicy(DataPolicy dataPolicy) { this.dataPolicy = dataPolicy; setHasDataPolicy(true); if (this.dataPolicy.withPartitioning() && !this.hasPartitionAttributes()) { setPartitionAttributes((new PartitionAttributesFactory()).create()); setHasPartitionAttributes(false); } }
@Override public Region createRegion(String regionName, Class valueConstraint) { PartitionAttributesFactory paf = new PartitionAttributesFactory(); AttributesFactory af = new AttributesFactory(); af.setPartitionAttributes(paf.create()); af.setValueConstraint(valueConstraint); Region r1 = CacheUtils.createRegion(regionName, af.create(), false); return r1; }
public static Region createFixedPartitionedRegion(final Cache cache, String regionName, List<FixedPartitionAttributes> fpaList, int localMaxMemory) { List<String> allPartitions = new ArrayList(); if (fpaList != null) { for (FixedPartitionAttributes fpa : fpaList) { allPartitions.add(fpa.getPartitionName()); } } else { allPartitions.add("Q1"); allPartitions.add("Q2"); } AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.setRedundantCopies(1); pfact.setLocalMaxMemory(localMaxMemory); if (fpaList != null) { for (FixedPartitionAttributes fpa : fpaList) { pfact.addFixedPartitionAttributes(fpa); } } pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions)); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).create(regionName); assertNotNull(r); return r; }
@Before public void setup() { InternalCache internalCache = Fakes.cache(); InternalResourceManager resourceManager = mock(InternalResourceManager.class, RETURNS_DEEP_STUBS); when(internalCache.getInternalResourceManager()).thenReturn(resourceManager); AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.setPartitionAttributes( new PartitionAttributesFactory().setTotalNumBuckets(1).setRedundantCopies(1).create()); partitionedRegion = new PartitionedRegion(regionName, attributesFactory.create(), null, internalCache, mock(InternalRegionArguments.class)); }
public static void createColocatedPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, Integer totalNumBuckets, String colocatedWith) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(totalNumBuckets); pfact.setColocatedWith(colocatedWith); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
public static void createPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, Boolean offHeap) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); fact.setPartitionAttributes(pfact.create()); fact.setOffHeap(offHeap); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
public static void createPartitionedRegionAccessorWithAsyncEventQueue(String regionName, String asyncEventQueueId) { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.setLocalMaxMemory(0); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); // fact.create()).create(regionName); assertNotNull(r); }
private static void setupPartitionedRegion(String regionName) { InternalCache cache = ClusterStartupRule.getCache(); PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create(); RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION); partitionRegionFactory.setPartitionAttributes(partitionAttrs); Region dataParRegion = partitionRegionFactory.create(regionName); assertThat(dataParRegion).isNotNull(); assertThat(dataParRegion.getFullPath()).contains(regionName); }
public static void createPartitionedRegionWithCacheLoaderAndAsyncQueue(String regionName, String asyncEventQueueId) { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); fact.setPartitionAttributes(pfact.create()); // set the CacheLoader implementation fact.setCacheLoader(new MyCacheLoader()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); }
private static void setupPartitionedRegion(String regionName) { InternalCache cache = ClusterStartupRule.getCache(); PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create(); RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION); partitionRegionFactory.setPartitionAttributes(partitionAttrs); Region dataParRegion = partitionRegionFactory.create(regionName); assertThat(dataParRegion).isNotNull(); assertThat(dataParRegion.getFullPath()).contains(regionName); }
@Before public void setUp() { prId = 0; path = null; partitionAttributes = new PartitionAttributesFactory().create(); scope = Scope.DISTRIBUTED_ACK; evictionAttributes = new EvictionAttributesImpl(); regionIdleTimeout = new ExpirationAttributes(); regionTimeToLive = new ExpirationAttributes(); entryIdleTimeout = new ExpirationAttributes(); entryTimeToLive = new ExpirationAttributes(); gatewaySenderIds = Collections.emptySet(); }
/** * This function creates Region attributes with provided scope,redundancy and localmaxMemory */ public static RegionAttributes createRegionAttrsForPR(int red, int localMaxMem, long recoveryDelay, EvictionAttributes evictionAttrs, PartitionResolver resolver) { AttributesFactory attr = new AttributesFactory(); attr.setDataPolicy(DataPolicy.PARTITION); PartitionAttributesFactory paf = new PartitionAttributesFactory(); paf.setRedundantCopies(red).setLocalMaxMemory(localMaxMem).setRecoveryDelay(recoveryDelay); if (resolver != null) { paf.setPartitionResolver(resolver); } PartitionAttributes<?, ?> prAttr = paf.create(); attr.setPartitionAttributes(prAttr); attr.setEvictionAttributes(evictionAttrs); return attr.create(); }
public static void createFixedPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, String partitionName, final List<String> allPartitions, boolean offHeap) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.addFixedPartitionAttributes( FixedPartitionAttributes.createFixedPartition(partitionName, true)); pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions)); fact.setPartitionAttributes(pfact.create()); fact.setOffHeap(offHeap); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
protected <K, V> Region<K, V> createRegion(final String regionName, final RegionShortcut regionShortCut, final String colocatedWithRegionName, final PartitionAttributes partitionAttributes, final RegionAttributes regionAttributes, PartitionListener lucenePrimaryBucketListener) { PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory(); if (lucenePrimaryBucketListener != null) { partitionAttributesFactory.addPartitionListener(lucenePrimaryBucketListener); } partitionAttributesFactory.setColocatedWith(colocatedWithRegionName); configureLuceneRegionAttributesFactory(partitionAttributesFactory, partitionAttributes); // Create AttributesFactory based on input RegionShortcut RegionAttributes baseAttributes = this.cache.getRegionAttributes(regionShortCut.toString()); AttributesFactory factory = new AttributesFactory(baseAttributes); factory.setPartitionAttributes(partitionAttributesFactory.create()); if (regionAttributes.getDataPolicy().withPersistence()) { factory.setDiskStoreName(regionAttributes.getDiskStoreName()); } RegionAttributes<K, V> attributes = factory.create(); return createRegion(regionName, attributes); }