I'm trying to use microstream (spring boot). I wrote a test class as demo. If I start the demo first time, it creates the session object and stores it in embedded storage. The second time session object is loaded again and "numValue" attribute is incremented. But all following runs, the numValue of stream is always 0. What do I missing?
There is the demo class
package test.microstream;
import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import one.microstream.integrations.spring.boot.types.Storage;
import one.microstream.storage.types.StorageManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
@Slf4j
public class MicrostreamApplication {
public static void main(String[] args) {
SpringApplication.run(MicrostreamApplication.class, args);
}
@AllArgsConstructor
@Data
@ToString
public static class DemoSession {
String account;
int numValue;
}
@Data
@ToString
@Storage
public static class DemoStorage {
Map<String, DemoSession> sessions;
@PostConstruct
public void init() {
if(sessions == null) {
sessions = new HashMap<>();
}
}
public void setSession(DemoSession session) {
sessions.put(session.getAccount(), session);
}
public DemoSession getSession(String account) {
return sessions.get(account);
}
}
@Autowired
DemoStorage storage;
@Autowired
StorageManager storageManager;
@Bean
public ApplicationRunner runner() {
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("root {}", storageManager.root());
log.info("storage {}", storage);
var session = storage.getSession("acc");
if(session == null) {
session = new DemoSession("acc", 0);
log.info("create session {}", session);
storage.setSession(session);
storageManager.storeRoot();
} else {
log.info("loaded session {}", session);
session.setNumValue(session.getNumValue()+1);
log.info("update session {}", session);
storageManager.storeRoot();
}
log.info("after all");
log.info("root {}", storageManager.root());
log.info("storage {}", storage);
}
};
}
}
There are outputs of the programm
2023-02-14T21:35:32.947+01:00 INFO 163817 --- [ main] one.microstream.util.logging.Logging : MicroStream Version 08.00.00-MS-EA2
2023-02-14T21:35:33.089+01:00 INFO 163817 --- [ main] .s.e.t.EmbeddedStorageFoundation$Default : Creating embedded storage manager
2023-02-14T21:35:33.206+01:00 INFO 163817 --- [ main] .t.PersistenceTypeHandlerManager$Default : Initializing type handler manager
2023-02-14T21:35:33.266+01:00 INFO 163817 --- [ main] o.m.s.e.t.EmbeddedStorageManager$Default : Starting embedded storage manager
2023-02-14T21:35:33.268+01:00 INFO 163817 --- [ main] o.m.storage.types.StorageSystem$Default : Starting storage system
2023-02-14T21:35:33.269+01:00 INFO 163817 --- [ main] .m.s.t.StorageStructureValidator$Default : Storage structure validated successfully.
2023-02-14T21:35:33.295+01:00 INFO 163817 --- [ main] .t.PersistenceTypeHandlerManager$Default : Initializing type handler manager
2023-02-14T21:35:33.308+01:00 INFO 163817 --- [ main] o.m.s.e.t.EmbeddedStorageManager$Default : Embedded storage manager initialized
2023-02-14T21:35:33.366+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : Started MicrostreamApplication in 0.963 seconds (process running for 1.278)
2023-02-14T21:35:33.367+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : root MicrostreamApplication.DemoStorage(sessions={acc=MicrostreamApplication.DemoSession(account=acc, numValue=0)})
2023-02-14T21:35:33.367+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : storage MicrostreamApplication.DemoStorage(sessions={acc=MicrostreamApplication.DemoSession(account=acc, numValue=0)})
2023-02-14T21:35:33.367+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : loaded session MicrostreamApplication.DemoSession(account=acc, numValue=0)
2023-02-14T21:35:33.367+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : update session MicrostreamApplication.DemoSession(account=acc, numValue=1)
2023-02-14T21:35:33.367+01:00 INFO 163817 --- [ main] .t.PersistenceTypeHandlerManager$Default : Initializing type handler manager
2023-02-14T21:35:33.372+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : after all
2023-02-14T21:35:33.372+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : root MicrostreamApplication.DemoStorage(sessions={acc=MicrostreamApplication.DemoSession(account=acc, numValue=1)})
2023-02-14T21:35:33.372+01:00 INFO 163817 --- [ main] t.microstream.MicrostreamApplication : storage MicrostreamApplication.DemoStorage(sessions={acc=MicrostreamApplication.DemoSession(account=acc, numValue=1)})
2023-02-14T21:45:18.225+01:00 INFO 163817 --- [ionShutdownHook] o.m.storage.types.StorageSystem$Default : Stopping storage system
2023-02-14T21:45:18.227+01:00 INFO 163817 --- [ionShutdownHook] o.m.storage.types.StorageSystem$Default : Storage system stopped
There are dependencies from the file
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>one.microstream</groupId>
<artifactId>microstream-storage-embedded</artifactId>
<version>08.00.00-MS-EA2</version>
</dependency>
<dependency>
<groupId>one.microstream</groupId>
<artifactId>microstream-integrations-spring-boot3</artifactId>
<version>08.00.00-MS-EA2</version>
</dependency>
<dependency>
<groupId>one.microstream</groupId>
<artifactId>microstream-storage-embedded-configuration</artifactId>
<version>08.00.00-MS-EA2</version>
</dependency>
</dependencies>
The file transaction*slt is growing every run. It looks like the new values are loaded, but every run the loaded root object is the same, in intial state.