use of com.hazelcast.memory.MemorySize in project hazelcast by hazelcast.
the class ConfigXmlGeneratorTest method testNativeMemory.
@Test
public void testNativeMemory() {
NativeMemoryConfig expectedConfig = new NativeMemoryConfig();
expectedConfig.setEnabled(true);
expectedConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.STANDARD);
expectedConfig.setMetadataSpacePercentage(12.5f);
expectedConfig.setMinBlockSize(50);
expectedConfig.setPageSize(100);
expectedConfig.setSize(new MemorySize(20, MemoryUnit.MEGABYTES));
Config config = new Config().setNativeMemoryConfig(expectedConfig);
Config xmlConfig = getNewConfigViaXMLGenerator(config);
NativeMemoryConfig actualConfig = xmlConfig.getNativeMemoryConfig();
assertTrue(actualConfig.isEnabled());
assertEquals(NativeMemoryConfig.MemoryAllocatorType.STANDARD, actualConfig.getAllocatorType());
assertEquals(12.5, actualConfig.getMetadataSpacePercentage(), 0.0001);
assertEquals(50, actualConfig.getMinBlockSize());
assertEquals(100, actualConfig.getPageSize());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getUnit(), actualConfig.getSize().getUnit());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getValue(), actualConfig.getSize().getValue());
assertEquals(expectedConfig, actualConfig);
}
use of com.hazelcast.memory.MemorySize in project hazelcast by hazelcast.
the class ConfigXmlGeneratorTest method testNativeMemoryWithPersistentMemory_SystemMemoryMode.
@Test
public void testNativeMemoryWithPersistentMemory_SystemMemoryMode() {
NativeMemoryConfig expectedConfig = new NativeMemoryConfig();
expectedConfig.setEnabled(true);
expectedConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.STANDARD);
expectedConfig.setMetadataSpacePercentage(12.5f);
expectedConfig.setMinBlockSize(50);
expectedConfig.setPageSize(100);
expectedConfig.setSize(new MemorySize(20, MemoryUnit.MEGABYTES));
expectedConfig.getPersistentMemoryConfig().setMode(PersistentMemoryMode.SYSTEM_MEMORY);
Config config = new Config().setNativeMemoryConfig(expectedConfig);
Config xmlConfig = getNewConfigViaXMLGenerator(config);
NativeMemoryConfig actualConfig = xmlConfig.getNativeMemoryConfig();
assertTrue(actualConfig.isEnabled());
assertEquals(NativeMemoryConfig.MemoryAllocatorType.STANDARD, actualConfig.getAllocatorType());
assertEquals(12.5, actualConfig.getMetadataSpacePercentage(), 0.0001);
assertEquals(50, actualConfig.getMinBlockSize());
assertEquals(100, actualConfig.getPageSize());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getUnit(), actualConfig.getSize().getUnit());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getValue(), actualConfig.getSize().getValue());
PersistentMemoryConfig pmemConfig = actualConfig.getPersistentMemoryConfig();
assertFalse(pmemConfig.isEnabled());
assertEquals(PersistentMemoryMode.SYSTEM_MEMORY, pmemConfig.getMode());
}
use of com.hazelcast.memory.MemorySize in project hazelcast by hazelcast.
the class ConfigXmlGeneratorTest method testNativeMemoryWithPersistentMemory.
@Test
public void testNativeMemoryWithPersistentMemory() {
NativeMemoryConfig expectedConfig = new NativeMemoryConfig();
expectedConfig.setEnabled(true);
expectedConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.STANDARD);
expectedConfig.setMetadataSpacePercentage(12.5f);
expectedConfig.setMinBlockSize(50);
expectedConfig.setPageSize(100);
expectedConfig.setSize(new MemorySize(20, MemoryUnit.MEGABYTES));
PersistentMemoryConfig origPmemConfig = expectedConfig.getPersistentMemoryConfig();
origPmemConfig.setEnabled(true);
origPmemConfig.addDirectoryConfig(new PersistentMemoryDirectoryConfig("/mnt/pmem0", 0));
origPmemConfig.addDirectoryConfig(new PersistentMemoryDirectoryConfig("/mnt/pmem1", 1));
Config config = new Config().setNativeMemoryConfig(expectedConfig);
Config xmlConfig = getNewConfigViaXMLGenerator(config);
NativeMemoryConfig actualConfig = xmlConfig.getNativeMemoryConfig();
assertTrue(actualConfig.isEnabled());
assertEquals(NativeMemoryConfig.MemoryAllocatorType.STANDARD, actualConfig.getAllocatorType());
assertEquals(12.5, actualConfig.getMetadataSpacePercentage(), 0.0001);
assertEquals(50, actualConfig.getMinBlockSize());
assertEquals(100, actualConfig.getPageSize());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getUnit(), actualConfig.getSize().getUnit());
assertEquals(new MemorySize(20, MemoryUnit.MEGABYTES).getValue(), actualConfig.getSize().getValue());
PersistentMemoryConfig pmemConfig = actualConfig.getPersistentMemoryConfig();
assertTrue(pmemConfig.isEnabled());
assertEquals(PersistentMemoryMode.MOUNTED, pmemConfig.getMode());
List<PersistentMemoryDirectoryConfig> directoryConfigs = pmemConfig.getDirectoryConfigs();
assertEquals(2, directoryConfigs.size());
assertEquals("/mnt/pmem0", directoryConfigs.get(0).getDirectory());
assertEquals(0, directoryConfigs.get(0).getNumaNode());
assertEquals("/mnt/pmem1", directoryConfigs.get(1).getDirectory());
assertEquals(1, directoryConfigs.get(1).getNumaNode());
assertEquals(expectedConfig, actualConfig);
}
use of com.hazelcast.memory.MemorySize in project hazelcast by hazelcast.
the class XMLConfigBuilderTest method testLocalDevice.
@Override
@Test
public void testLocalDevice() {
String baseDir = "base-directory";
int blockSize = 2048;
int readIOThreadCount = 16;
int writeIOThreadCount = 1;
String xml = HAZELCAST_START_TAG + "<local-device name=\"my-device\">" + " <base-dir>" + baseDir + "</base-dir>" + " <block-size>" + blockSize + "</block-size>" + " <capacity value=\"100\" unit=\"GIGABYTES\"/>" + " <read-io-thread-count>" + readIOThreadCount + "</read-io-thread-count>" + " <write-io-thread-count>" + writeIOThreadCount + "</write-io-thread-count>" + "</local-device>\n" + HAZELCAST_END_TAG;
Config config = new InMemoryXmlConfig(xml);
LocalDeviceConfig localDeviceConfig = config.getDeviceConfig("my-device");
assertNotNull(localDeviceConfig);
assertEquals("my-device", localDeviceConfig.getName());
assertEquals(new File(baseDir).getAbsolutePath(), localDeviceConfig.getBaseDir().getAbsolutePath());
assertEquals(blockSize, localDeviceConfig.getBlockSize());
assertEquals(new MemorySize(100, MemoryUnit.GIGABYTES), localDeviceConfig.getCapacity());
assertEquals(readIOThreadCount, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount, localDeviceConfig.getWriteIOThreadCount());
int device0Multiplier = 2;
int device1Multiplier = 4;
xml = HAZELCAST_START_TAG + "<local-device name=\"device0\">" + " <capacity value=\"1234567890\" unit=\"MEGABYTES\"/>" + " <block-size>" + (blockSize * device0Multiplier) + "</block-size>" + " <read-io-thread-count>" + (readIOThreadCount * device0Multiplier) + "</read-io-thread-count>" + " <write-io-thread-count>" + (writeIOThreadCount * device0Multiplier) + "</write-io-thread-count>" + "</local-device>\n" + "<local-device name=\"device1\">" + " <block-size>" + (blockSize * device1Multiplier) + "</block-size>" + " <read-io-thread-count>" + (readIOThreadCount * device1Multiplier) + "</read-io-thread-count>" + " <write-io-thread-count>" + (writeIOThreadCount * device1Multiplier) + "</write-io-thread-count>" + "</local-device>\n" + HAZELCAST_END_TAG;
config = new InMemoryXmlConfig(xml);
assertEquals(3, config.getDeviceConfigs().size());
localDeviceConfig = config.getDeviceConfig("device0");
assertEquals(blockSize * device0Multiplier, localDeviceConfig.getBlockSize());
assertEquals(readIOThreadCount * device0Multiplier, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount * device0Multiplier, localDeviceConfig.getWriteIOThreadCount());
assertEquals(new MemorySize(1234567890, MemoryUnit.MEGABYTES), localDeviceConfig.getCapacity());
localDeviceConfig = config.getDeviceConfig("device1");
assertEquals(blockSize * device1Multiplier, localDeviceConfig.getBlockSize());
assertEquals(readIOThreadCount * device1Multiplier, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount * device1Multiplier, localDeviceConfig.getWriteIOThreadCount());
// default device
localDeviceConfig = config.getDeviceConfig(DEFAULT_DEVICE_NAME);
assertEquals(DEFAULT_DEVICE_NAME, localDeviceConfig.getName());
assertEquals(new File(DEFAULT_DEVICE_BASE_DIR).getAbsoluteFile(), localDeviceConfig.getBaseDir());
assertEquals(DEFAULT_BLOCK_SIZE_IN_BYTES, localDeviceConfig.getBlockSize());
assertEquals(DEFAULT_READ_IO_THREAD_COUNT, localDeviceConfig.getReadIOThreadCount());
assertEquals(DEFAULT_WRITE_IO_THREAD_COUNT, localDeviceConfig.getWriteIOThreadCount());
assertEquals(LocalDeviceConfig.DEFAULT_CAPACITY, localDeviceConfig.getCapacity());
// override the default device config
String newBaseDir = "/some/random/base/dir/for/tiered/store";
xml = HAZELCAST_START_TAG + "<local-device name=\"" + DEFAULT_DEVICE_NAME + "\">" + " <base-dir>" + newBaseDir + "</base-dir>" + " <block-size>" + (DEFAULT_BLOCK_SIZE_IN_BYTES * 2) + "</block-size>" + " <read-io-thread-count>" + (DEFAULT_READ_IO_THREAD_COUNT * 2) + "</read-io-thread-count>" + "</local-device>\n" + HAZELCAST_END_TAG;
config = new InMemoryXmlConfig(xml);
assertEquals(1, config.getDeviceConfigs().size());
localDeviceConfig = config.getDeviceConfig(DEFAULT_DEVICE_NAME);
assertEquals(DEFAULT_DEVICE_NAME, localDeviceConfig.getName());
assertEquals(new File(newBaseDir).getAbsoluteFile(), localDeviceConfig.getBaseDir());
assertEquals(2 * DEFAULT_BLOCK_SIZE_IN_BYTES, localDeviceConfig.getBlockSize());
assertEquals(2 * DEFAULT_READ_IO_THREAD_COUNT, localDeviceConfig.getReadIOThreadCount());
assertEquals(DEFAULT_WRITE_IO_THREAD_COUNT, localDeviceConfig.getWriteIOThreadCount());
}
use of com.hazelcast.memory.MemorySize in project hazelcast by hazelcast.
the class YamlConfigBuilderTest method testLocalDevice.
@Override
@Test
public void testLocalDevice() {
String baseDir = "base-directory";
int blockSize = 2048;
int readIOThreadCount = 16;
int writeIOThreadCount = 1;
String yaml = "" + "hazelcast:\n" + " local-device:\n" + " my-device:\n" + " base-dir: " + baseDir + "\n" + " capacity:\n" + " unit: GIGABYTES\n" + " value: 100\n" + " block-size: " + blockSize + "\n" + " read-io-thread-count: " + readIOThreadCount + "\n" + " write-io-thread-count: " + writeIOThreadCount + "\n";
Config config = new InMemoryYamlConfig(yaml);
LocalDeviceConfig localDeviceConfig = config.getDeviceConfig("my-device");
assertEquals("my-device", localDeviceConfig.getName());
assertEquals(new File(baseDir).getAbsolutePath(), localDeviceConfig.getBaseDir().getAbsolutePath());
assertEquals(blockSize, localDeviceConfig.getBlockSize());
assertEquals(new MemorySize(100, MemoryUnit.GIGABYTES), localDeviceConfig.getCapacity());
assertEquals(readIOThreadCount, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount, localDeviceConfig.getWriteIOThreadCount());
int device0Multiplier = 2;
int device1Multiplier = 4;
yaml = "" + "hazelcast:\n" + " local-device:\n" + " device0:\n" + " capacity:\n" + " unit: MEGABYTES\n" + " value: 1234567890\n" + " block-size: " + (blockSize * device0Multiplier) + "\n" + " read-io-thread-count: " + (readIOThreadCount * device0Multiplier) + "\n" + " write-io-thread-count: " + (writeIOThreadCount * device0Multiplier) + "\n" + " device1:\n" + " block-size: " + (blockSize * device1Multiplier) + "\n" + " read-io-thread-count: " + (readIOThreadCount * device1Multiplier) + "\n" + " write-io-thread-count: " + (writeIOThreadCount * device1Multiplier) + "\n";
config = new InMemoryYamlConfig(yaml);
assertEquals(3, config.getDeviceConfigs().size());
localDeviceConfig = config.getDeviceConfig("device0");
assertEquals(blockSize * device0Multiplier, localDeviceConfig.getBlockSize());
assertEquals(readIOThreadCount * device0Multiplier, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount * device0Multiplier, localDeviceConfig.getWriteIOThreadCount());
assertEquals(new MemorySize(1234567890, MemoryUnit.MEGABYTES), localDeviceConfig.getCapacity());
localDeviceConfig = config.getDeviceConfig("device1");
assertEquals(blockSize * device1Multiplier, localDeviceConfig.getBlockSize());
assertEquals(readIOThreadCount * device1Multiplier, localDeviceConfig.getReadIOThreadCount());
assertEquals(writeIOThreadCount * device1Multiplier, localDeviceConfig.getWriteIOThreadCount());
// default device
localDeviceConfig = config.getDeviceConfig(DEFAULT_DEVICE_NAME);
assertEquals(DEFAULT_DEVICE_NAME, localDeviceConfig.getName());
assertEquals(new File(DEFAULT_DEVICE_BASE_DIR).getAbsoluteFile(), localDeviceConfig.getBaseDir());
assertEquals(DEFAULT_BLOCK_SIZE_IN_BYTES, localDeviceConfig.getBlockSize());
assertEquals(DEFAULT_READ_IO_THREAD_COUNT, localDeviceConfig.getReadIOThreadCount());
assertEquals(DEFAULT_WRITE_IO_THREAD_COUNT, localDeviceConfig.getWriteIOThreadCount());
assertEquals(LocalDeviceConfig.DEFAULT_CAPACITY, localDeviceConfig.getCapacity());
// override the default device config
String newBaseDir = "/some/random/base/dir/for/tiered/store";
yaml = "" + "hazelcast:\n" + " local-device:\n" + " " + DEFAULT_DEVICE_NAME + ":\n" + " base-dir: " + newBaseDir + "\n" + " block-size: " + (DEFAULT_BLOCK_SIZE_IN_BYTES * 2) + "\n" + " read-io-thread-count: " + (DEFAULT_READ_IO_THREAD_COUNT * 2) + "\n";
config = new InMemoryYamlConfig(yaml);
assertEquals(1, config.getDeviceConfigs().size());
localDeviceConfig = config.getDeviceConfig(DEFAULT_DEVICE_NAME);
assertEquals(DEFAULT_DEVICE_NAME, localDeviceConfig.getName());
assertEquals(new File(newBaseDir).getAbsoluteFile(), localDeviceConfig.getBaseDir());
assertEquals(2 * DEFAULT_BLOCK_SIZE_IN_BYTES, localDeviceConfig.getBlockSize());
assertEquals(2 * DEFAULT_READ_IO_THREAD_COUNT, localDeviceConfig.getReadIOThreadCount());
assertEquals(DEFAULT_WRITE_IO_THREAD_COUNT, localDeviceConfig.getWriteIOThreadCount());
}
Aggregations