/** * Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified maximum mapping size to the configured * builder. * <p> * {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}. * * @param size the maximum mapping size * @param unit the memory unit * @return a new builder with the added / updated configuration */ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectSize(long size, MemoryUnit unit) { return mapServiceConfiguration(DefaultSizeOfEngineConfiguration.class, existing -> ofNullable(existing) .map(e -> new DefaultSizeOfEngineConfiguration(size, unit, e.getMaxObjectGraphSize())) .orElse(new DefaultSizeOfEngineConfiguration(size, unit, DEFAULT_OBJECT_GRAPH_SIZE))); }
/** * Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified object graph maximum size to the configured * builder. * <p> * {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}. * * @param size the maximum graph size * @return a new builder with the added / updated configuration */ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectGraph(long size) { return mapServiceConfiguration(DefaultSizeOfEngineConfiguration.class, existing -> ofNullable(existing) .map(e -> new DefaultSizeOfEngineConfiguration(e.getMaxObjectSize(), e.getUnit(), size)) .orElse(new DefaultSizeOfEngineConfiguration(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_UNIT, size))); }
@Test public void testIllegalMaxObjectSizeArgument() { try { new DefaultSizeOfEngineConfiguration(0, MemoryUnit.B, 1l); fail(); } catch (Exception illegalArgument) { assertThat(illegalArgument, instanceOf(IllegalArgumentException.class)); assertThat(illegalArgument.getMessage(), equalTo("ObjectGraphSize/ObjectSize can only accept positive values.")); } }
@Test public void testIllegalMaxObjectGraphSizeArgument() { try { new DefaultSizeOfEngineConfiguration(1l, MemoryUnit.B, 0); fail(); } catch (Exception illegalArgument) { assertThat(illegalArgument, instanceOf(IllegalArgumentException.class)); assertThat(illegalArgument.getMessage(), equalTo("ObjectGraphSize/ObjectSize can only accept positive values.")); } }
@Test public void testValidArguments() { DefaultSizeOfEngineConfiguration configuration = new DefaultSizeOfEngineConfiguration(10l, MemoryUnit.B, 10l); assertThat(configuration.getMaxObjectGraphSize(), equalTo(10l)); assertThat(configuration.getMaxObjectSize(), equalTo(10l)); assertThat(configuration.getUnit(), equalTo(MemoryUnit.B)); }
public DefaultSizeOfEngineConfigurationParser() { super(DefaultSizeOfEngineConfiguration.class, CacheTemplate::heapStoreSettings, config -> new DefaultSizeOfEngineConfiguration(config.getMaxObjectSize(), config.getUnit(), config.getMaxObjectGraphSize()), CacheType::getHeapStoreSettings, CacheType::setHeapStoreSettings, config -> new SizeofType() .withMaxObjectGraphSize(new SizeofType.MaxObjectGraphSize().withValue(BigInteger.valueOf(config.getMaxObjectGraphSize()))) .withMaxObjectSize(new MemoryType() .withValue(BigInteger.valueOf(config.getMaxObjectSize())) .withUnit(MemoryUnit.fromValue(config.getUnit().toString())) )); } }
@Test public void unparseServiceConfiguration() { CacheConfiguration<?, ?> cacheConfig = newCacheConfigurationBuilder(Object.class, Object.class, heap(10)).add(new DefaultSizeOfEngineConfiguration(123, MemoryUnit.MB, 987)).build(); CacheType cacheType = new CacheType(); cacheType = new DefaultSizeOfEngineConfigurationParser().unparseServiceConfiguration(cacheConfig, cacheType); SizeofType heapStore = cacheType.getHeapStoreSettings(); assertThat(heapStore.getMaxObjectGraphSize().getValue()).isEqualTo(987); assertThat(heapStore.getMaxObjectSize().getValue()).isEqualTo(123); assertThat(heapStore.getMaxObjectSize().getUnit().value()).isEqualTo("MB"); } }
/** * Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified maximum mapping size to the configured * builder. * <p> * {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}. * * @param size the maximum mapping size * @param unit the memory unit * @return a new builder with the added / updated configuration */ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectSize(long size, MemoryUnit unit) { return mapServiceConfiguration(DefaultSizeOfEngineConfiguration.class, existing -> ofNullable(existing) .map(e -> new DefaultSizeOfEngineConfiguration(size, unit, e.getMaxObjectGraphSize())) .orElse(new DefaultSizeOfEngineConfiguration(size, unit, DEFAULT_OBJECT_GRAPH_SIZE))); }
/** * Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified object graph maximum size to the configured * builder. * <p> * {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}. * * @param size the maximum graph size * @return a new builder with the added / updated configuration */ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectGraph(long size) { return mapServiceConfiguration(DefaultSizeOfEngineConfiguration.class, existing -> ofNullable(existing) .map(e -> new DefaultSizeOfEngineConfiguration(e.getMaxObjectSize(), e.getUnit(), size)) .orElse(new DefaultSizeOfEngineConfiguration(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_UNIT, size))); }
public DefaultSizeOfEngineConfigurationParser() { super(DefaultSizeOfEngineConfiguration.class, CacheTemplate::heapStoreSettings, config -> new DefaultSizeOfEngineConfiguration(config.getMaxObjectSize(), config.getUnit(), config.getMaxObjectGraphSize()), CacheType::getHeapStoreSettings, CacheType::setHeapStoreSettings, config -> new SizeofType() .withMaxObjectGraphSize(new SizeofType.MaxObjectGraphSize().withValue(BigInteger.valueOf(config.getMaxObjectGraphSize()))) .withMaxObjectSize(new MemoryType() .withValue(BigInteger.valueOf(config.getMaxObjectSize())) .withUnit(MemoryUnit.fromValue(config.getUnit().toString())) )); } }