/** Appends to a StringBuffer logging that describes a DiskSTore for the * given Region. * @param aRegion The Region possibly containing a DiskStore. * @param aStr The StringBuffer to append to. */ public static void logDiskStore(Region aRegion, StringBuffer aStr) { if (aRegion.getAttributes().getDiskStoreName() != null) { aStr.append(" diskStoreName " + aRegion.getAttributes().getDiskStoreName()); } }
/** Create the DiskStore if the RegionAttributes specifies it. * * @param attr The RegionAttributes that could specify a DiskStore. * @return A String description of the DiskStore, useful for logging. */ public static String createDiskStore(RegionAttributes attr) { String diskDirsStr = ""; Log.getLogWriter().info("DiskStore name in attributes is " + attr.getDiskStoreName()); if ((attr.getDiskStoreName() != null) && (!attr.getDiskStoreName().equals("notUsed"))) { Log.getLogWriter().info("Creating diskStore " + attr.getDiskStoreName()); DiskStoreFactory dsFactory = DiskStoreHelper.getDiskStoreFactory(attr.getDiskStoreName()); dsFactory.create(attr.getDiskStoreName()); File[] diskDirs = CacheHelper.getCache().findDiskStore(attr.getDiskStoreName()).getDiskDirs(); for (File diskDir: diskDirs) { diskDirsStr = diskDirsStr + diskDir.getName() + " "; } diskDirsStr = " with disk dirs " + diskDirsStr; } return "disk store name is " + attr.getDiskStoreName() + " " + diskDirsStr; }
protected String getDiskStoreName(final Region region) { return StringUtils.defaultIfBlank(region.getAttributes().getDiskStoreName(), DiskStoreDetails.DEFAULT_DISK_STORE_NAME); }
protected String getDiskStoreName(final Region region) { return StringUtils.defaultIfBlank(region.getAttributes().getDiskStoreName(), DiskStoreDetails.DEFAULT_DISK_STORE_NAME); }
/** Choose a random DiskStore and set it in the attributes factory. * * @param baseAttr The region attributes we start with (without a DiskStore set) * @param attrFac The attributes factory to set the DiskStore in. * @param diskStoreNames A List of potential DiskStore names to choose from. * @param rand The random number generator used while creating regions and attributes. */ public static void setRandomDiskStore(RegionAttributes baseAttr, AttributesFactory attrFac, List<String> diskStoreNames, GsRandom rand) { if ((baseAttr.getDiskStoreName() != null) && (baseAttr.getDiskStoreName().equals("notUsed"))) { // disk store should be chosen randomly // setting the diskStoreName to unused is a signal that we do need a disk store and to choose randomly String diskStoreName = diskStoreNames.get(rand.nextInt(1, diskStoreNames.size()-1)); if (diskStoreName.equals("unused")) { throw new TestException("Error in test, diskStoreName is " + diskStoreName); } Log.getLogWriter().info("Test is setting diskStoreName to " + diskStoreName); attrFac.setDiskStoreName(diskStoreName); } }
public void testResolveReplacePropertyStringForNonLonerCache(){ Properties props = new Properties(); props.setProperty("mcast-port", "10333"); props.setProperty("locators", ""); System.setProperty("gemfirePropertyFile", BUG_40255_PROPS); props.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, BUG_40255_XML); System.setProperty(NESTED_ATTR_PROPERTY_STRING, NESTED_ATTR_PROPERTY_VALUE); System.setProperty(ATTR_PROPERTY_STRING, ATTR_PROPERTY_VALUE); System.setProperty(ELEMENT_PROPERTY_STRING, ELEMENT_PROPERTY_VALUE); System.setProperty(CONCAT_ELEMENT_PROPERTY_STRING, CONCAT_ELEMENT_PROPERTY_VALUE); // create the directory where data is going to be stored File dir = new File("persistData1"); dir.mkdir(); this.ds = DistributedSystem.connect(props); this.cache = CacheFactory.create(this.ds); Region exampleRegion = this.cache.getRegion("example-region"); RegionAttributes<Object, Object> attrs = exampleRegion.getAttributes(); //Check if disk store got same name as passed in system properties in setup(). assertEquals(attrs.getDiskStoreName(), System.getProperty(ATTR_PROPERTY_STRING)); assertNotNull(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE)); assertEquals(exampleRegion.get(ELEMENT_PROPERTY_VALUE+CONCAT_ELEMENT_PROPERTY_VALUE), ELEMENT_KEY_VALUE); }
private void setDiskAttributes(BucketAttributesFactory factory) { factory.setDiskSynchronous(this.partitionedRegion.getAttributes().isDiskSynchronous()); factory.setDiskStoreName(this.partitionedRegion.getAttributes().getDiskStoreName()); }
private void setDiskAttributes(BucketAttributesFactory factory) { factory.setDiskSynchronous(this.partitionedRegion.getAttributes().isDiskSynchronous()); factory.setDiskStoreName(this.partitionedRegion.getAttributes().getDiskStoreName()); }
@Override public Set<SortedIndexContainer> getAllLocalIndexes( final DiskStoreImpl ds) { final GemFireStore memStore = Misc.getMemStoreBooting(); @SuppressWarnings("unchecked") Set<SortedIndexContainer> allIndexes = new THashSet(); for (GemFireContainer container : memStore.getAllContainers()) { if (container.isLocalIndex() && container.isInitialized()) { // check if index will use the provided diskstore for persistence if (ds == null || ds.getName().equals(container.getBaseContainer() .getRegionAttributes().getDiskStoreName())) { assert ds == null || ds == container.getBaseContainer().getRegion() .getDiskStore(): "ds=" + ds + ", regionDS=" + container.getBaseContainer().getRegion().getDiskStore(); allIndexes.add(container); } } } return allIndexes; }
@Override public Set<SortedIndexContainer> getAllLocalIndexes( final DiskStoreImpl ds) { final GemFireStore memStore = Misc.getMemStoreBooting(); @SuppressWarnings("unchecked") Set<SortedIndexContainer> allIndexes = new THashSet(); for (GemFireContainer container : memStore.getAllContainers()) { if (container.isLocalIndex() && container.isInitialized()) { // check if index will use the provided diskstore for persistence if (ds == null || ds.getName().equals(container.getBaseContainer() .getRegionAttributes().getDiskStoreName())) { assert ds == null || ds == container.getBaseContainer().getRegion() .getDiskStore(): "ds=" + ds + ", regionDS=" + container.getBaseContainer().getRegion().getDiskStore(); allIndexes.add(container); } } } return allIndexes; }
@Override public Set<SortedIndexContainer> getAllLocalIndexes( final DiskStoreImpl ds) { final GemFireStore memStore = Misc.getMemStoreBooting(); @SuppressWarnings("unchecked") Set<SortedIndexContainer> allIndexes = new THashSet(); for (GemFireContainer container : memStore.getAllContainers()) { if (container.isLocalIndex() && container.isInitialized()) { // check if index will use the provided diskstore for persistence if (ds == null || ds.getName().equals(container.getBaseContainer() .getRegionAttributes().getDiskStoreName())) { assert ds == null || ds == container.getBaseContainer().getRegion() .getDiskStore(): "ds=" + ds + ", regionDS=" + container.getBaseContainer().getRegion().getDiskStore(); allIndexes.add(container); } } } return allIndexes; }
public void testSetDiskStoreName() throws CacheException, IOException { Cache c = createCache(); c.createDiskStoreFactory().create("ds"); Region r1 = null; try { RegionFactory factory = c.createRegionFactory(LOCAL_PERSISTENT); r1 = factory.setDiskStoreName("ds").create(this.r1Name); RegionAttributes ra = r1.getAttributes(); assertEquals("ds", ra.getDiskStoreName()); } finally { cleanUpRegion(r1); } }
public void testSetDiskStoreName() throws CacheException, IOException { ClientCache c = new ClientCacheFactory().create(); c.createDiskStoreFactory().create("ds"); Region r1 = null; try { ClientRegionFactory factory = c.createClientRegionFactory(LOCAL_PERSISTENT); r1 = factory.setDiskStoreName("ds").create(this.r1Name); RegionAttributes ra = r1.getAttributes(); assertEquals("ds", ra.getDiskStoreName()); } finally { cleanUpRegion(r1); } }
@Test public void testGetRegionDiskStoreName() { final String expectedDiskStoreName = "testDiskStore"; final Region mockRegion = mockContext.mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mockContext.mock(RegionAttributes.class, "RegionAttributes"); mockContext.checking(new Expectations() {{ oneOf(mockRegion).getAttributes(); will(returnValue(mockRegionAttributes)); oneOf(mockRegionAttributes).getDiskStoreName(); will(returnValue(expectedDiskStoreName)); }}); final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); assertEquals(expectedDiskStoreName, function.getDiskStoreName(mockRegion)); }
@Test public void testGetRegionDiskStoreNameWhenUnspecified() { final Region mockRegion = mockContext.mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mockContext.mock(RegionAttributes.class, "RegionAttributes"); mockContext.checking(new Expectations() {{ oneOf(mockRegion).getAttributes(); will(returnValue(mockRegionAttributes)); oneOf(mockRegionAttributes).getDiskStoreName(); will(returnValue(null)); }}); final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockRegion)); }
public static void assertEquals(RegionAttributes ra1, RegionAttributes ra2) { assertEquals(ra1.getScope(), ra2.getScope()); assertEquals(ra1.getKeyConstraint(), ra2.getKeyConstraint()); assertEquals(ra1.getValueConstraint(), ra2.getValueConstraint()); assertEquals(ra1.getCacheListener(), ra2.getCacheListener()); assertEquals(ra1.getCacheWriter(), ra2.getCacheWriter()); assertEquals(ra1.getCacheLoader(), ra2.getCacheLoader()); assertEquals(ra1.getStatisticsEnabled(), ra2.getStatisticsEnabled()); assertEquals(ra1.getConcurrencyLevel(), ra2.getConcurrencyLevel()); assertEquals(ra1.getInitialCapacity(), ra2.getInitialCapacity()); assertTrue(ra1.getLoadFactor() == ra2.getLoadFactor()); assertEquals(ra1.getEarlyAck(), ra2.getEarlyAck()); assertEquals(ra1.isDiskSynchronous(), ra2.isDiskSynchronous()); assertEquals(ra1.getDiskStoreName(), ra2.getDiskStoreName()); }
public static void assertEquals(RegionAttributes ra1, RegionAttributes ra2) { assertEquals(ra1.getScope(), ra2.getScope()); assertEquals(ra1.getKeyConstraint(), ra2.getKeyConstraint()); assertEquals(ra1.getValueConstraint(), ra2.getValueConstraint()); assertEquals(ra1.getCacheListener(), ra2.getCacheListener()); assertEquals(ra1.getCacheWriter(), ra2.getCacheWriter()); assertEquals(ra1.getCacheLoader(), ra2.getCacheLoader()); assertEquals(ra1.getStatisticsEnabled(), ra2.getStatisticsEnabled()); assertEquals(ra1.getConcurrencyLevel(), ra2.getConcurrencyLevel()); assertEquals(ra1.getInitialCapacity(), ra2.getInitialCapacity()); assertTrue(ra1.getLoadFactor() == ra2.getLoadFactor()); assertEquals(ra1.getEarlyAck(), ra2.getEarlyAck()); assertEquals(ra1.isDiskSynchronous(), ra2.isDiskSynchronous()); assertEquals(ra1.getDiskStoreName(), ra2.getDiskStoreName()); }
@Test public void testIsRegionUsingDiskStoreWhenUsingDefaultDiskStore() { final Region mockRegion = mockContext.mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mockContext.mock(RegionAttributes.class, "RegionAttributes"); final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore"); mockContext.checking(new Expectations() {{ atLeast(1).of(mockRegion).getAttributes(); will(returnValue(mockRegionAttributes)); oneOf(mockRegionAttributes).getDataPolicy(); will(returnValue(DataPolicy.PERSISTENT_REPLICATE)); oneOf(mockRegionAttributes).getDiskStoreName(); will(returnValue(null)); oneOf(mockDiskStore).getName(); will(returnValue(DiskStoreDetails.DEFAULT_DISK_STORE_NAME)); }}); final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); assertTrue(function.isUsingDiskStore(mockRegion, mockDiskStore)); }
@Test public void testIsRegionUsingDiskStoreWhenDiskStoresMismatch() { final Region mockRegion = mockContext.mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mockContext.mock(RegionAttributes.class, "RegionAttributes"); final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore"); mockContext.checking(new Expectations() {{ atLeast(1).of(mockRegion).getAttributes(); will(returnValue(mockRegionAttributes)); oneOf(mockRegionAttributes).getDataPolicy(); will(returnValue(DataPolicy.PERSISTENT_PARTITION)); oneOf(mockRegionAttributes).getDiskStoreName(); will(returnValue("mockDiskStore")); oneOf(mockDiskStore).getName(); will(returnValue("testDiskStore")); }}); final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); assertFalse(function.isUsingDiskStore(mockRegion, mockDiskStore)); }
@Test public void testIsRegionUsingDiskStoreWhenPersistent() { final String diskStoreName = "testDiskStore"; final Region mockRegion = mockContext.mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mockContext.mock(RegionAttributes.class, "RegionAttributes"); final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore"); mockContext.checking(new Expectations() {{ atLeast(1).of(mockRegion).getAttributes(); will(returnValue(mockRegionAttributes)); oneOf(mockRegionAttributes).getDataPolicy(); will(returnValue(DataPolicy.PERSISTENT_PARTITION)); oneOf(mockRegionAttributes).getDiskStoreName(); will(returnValue(diskStoreName)); oneOf(mockDiskStore).getName(); will(returnValue(diskStoreName)); }}); final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); assertTrue(function.isUsingDiskStore(mockRegion, mockDiskStore)); }