/** * Set a random DiskStore for the region defined with regionConfigName if it is persistent or has * eviction with overflow to disk. * * @param regionConfigName A hydra region config name. return factory The attributes factory for * the regionConfigName with possibly a DiskStore. */ public static AttributesFactory setDiskStoreIfNeeded(String regionConfigName) { AttributesFactory factory = RegionHelper.getAttributesFactory(regionConfigName); RegionDescription desc = RegionHelper.getRegionDescription(regionConfigName); EvictionAttributes evAttr = desc.getEvictionAttributes(); if ((desc.getDataPolicy().withPersistence()) || ((evAttr != null) && (evAttr.getAction().isOverflowToDisk()))) { List diskStoreNames = TestConfig.tab().vecAt(DiskStorePrms.names); factory.setDiskStoreName( (String) (diskStoreNames.get( TestConfig.tab().getRandGen().nextInt(1, diskStoreNames.size() - 1)))); } return factory; }
protected RegionAttributes getDiskRegionAttributes() { AttributesFactory factory = new AttributesFactory(getRegionAttributes()); File[] diskDirs = new File[1]; diskDirs[0] = new File("diskRegionDirs/" + OSProcess.getId()); diskDirs[0].mkdirs(); factory.setDiskStoreName( getCache() .createDiskStoreFactory() .setDiskDirs(diskDirs) .setTimeInterval(1000) .setQueueSize(0) .create("TXRestrictionsDUnitTest") .getName()); factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); return factory.create(); }
/** * 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); } }