Skip to content

Commit

Permalink
Enable microstream cache (#351)
Browse files Browse the repository at this point in the history
* Add support to load a new cache

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>

* Create Storage Cache test

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>

* Optmizes the log message to configuration supplier

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>

* Add Storage test integration

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>

* Add test in the Storage Cache

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava authored Apr 27, 2022
1 parent 5812a5d commit ab6c99b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Objects;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.cache.configuration.Factory;
Expand All @@ -32,6 +33,7 @@
import javax.cache.integration.CacheWriter;
import javax.enterprise.inject.Instance;

import one.microstream.cache.types.CacheStore;
import org.eclipse.microprofile.config.Config;

import one.microstream.storage.types.StorageManager;
Expand Down Expand Up @@ -60,7 +62,6 @@ class MutableConfigurationSupplier<K, V> implements Supplier<MutableConfiguratio
private final Factory<CacheWriter<K, V>> writerFactory ;
private final Factory<ExpiryPolicy> expiryFactory ;

@SuppressWarnings("unused") // (17.03.2022 FH) XXX: check why it is not used
private final Instance<StorageManager> storageManager;

private MutableConfigurationSupplier(
Expand Down Expand Up @@ -143,13 +144,14 @@ public MutableConfiguration<K, V> get()
}
if(this.storage)
{
LOGGER.warning("The storage option is disable so, we'll ignore this option");
// StorageManager storageManager = this.storageManager.get();
// CacheStore<K, V> cacheStore = CacheStore.New(cacheProperty.getName(),storageManager);
// configuration.setCacheLoaderFactory(() -> cacheStore);
// configuration.setCacheWriterFactory(() -> cacheStore);
// configuration.setWriteThrough(true);
// configuration.setWriteThrough(true);
LOGGER.log(Level.FINE, "Using the storage option to this cache, so it will enable write and read through");
StorageManager storageManager = this.storageManager.get();
CacheStore<K, V> cacheStore = CacheStore.New(cacheProperty.getName(),storageManager);
configuration.setCacheLoaderFactory(() -> cacheStore);
configuration.setCacheWriterFactory(() -> cacheStore);
configuration.setWriteThrough(true);
configuration.setReadThrough(true);

}
return configuration;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package one.microstream.integrations.cdi.types.cache;
/*-
* #%L
* microstream-integrations-cdi
* %%
* Copyright (C) 2019 - 2022 MicroStream Software
* %%
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is
* available at https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
* #L%
*/

import one.microstream.integrations.cdi.types.ConfigurationCoreProperties;
import one.microstream.integrations.cdi.types.test.CDIExtension;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.cache.Cache;
import javax.inject.Inject;

import static one.microstream.integrations.cdi.types.ConfigurationCoreProperties.STORAGE_DIRECTORY;

@CDIExtension
public class StorageCacheTest {

@Inject
@StorageCache("storage")
private Cache<Integer, String> cache;

@BeforeAll
public static void beforeAll() {
System.setProperty(CacheProperties.STORAGE.get(), Boolean.TRUE.toString());
System.setProperty(STORAGE_DIRECTORY.getMicroprofile(), "target/cache");
}

@AfterAll
public static void afterAll() {
System.clearProperty(CacheProperties.STORAGE.get());
System.clearProperty(STORAGE_DIRECTORY.getMicroprofile());
}

@Test
public void shouldCreateStorableInstance(){
Assertions.assertNotNull(cache);
}

@Test
public void shouldCreateValues() {
cache.put(1, "one");
Assertions.assertNotNull(cache.get(1));
}

}

0 comments on commit ab6c99b

Please sign in to comment.