Hello,
I encountered again the issue I reported in #506.
We are using Javers with Spring boot and H2 as the test database. Before each test we truncate all the tables and reset the sequences. We don't reinitialize the Spring context before each test because it is quite time consuming. Therefore, we need to reset any state/cache before each test, including the sequecne cache in SequenceAllocation.
Basically, if we don't clear the sequence cache, the following situation might happen (assuming 50 as the size of the sequence batch):
Before test A: spring context is initialized.
Before test A: all tables are truncated and all sequences are reset
In test A: sequence numbers 1 to 50 are cached and JaVers uses sequence 1 to 30.
Before test B: all tables are truncated and all sequences are reset
In test B: sequence numbers 31 to 50 are still in the cache. JaVers uses these values and ask the DB for the next batch of sequence numbers, which are again 1 to 50. JaVers uses these values but when it want to store a row in the DB with sequence number 31, an exception occurs since a row with this primary key already exists.
Hello,
I encountered again the issue I reported in #506.
We are using Javers with Spring boot and H2 as the test database. Before each test we truncate all the tables and reset the sequences. We don't reinitialize the Spring context before each test because it is quite time consuming. Therefore, we need to reset any state/cache before each test, including the sequecne cache in SequenceAllocation.
Basically, if we don't clear the sequence cache, the following situation might happen (assuming 50 as the size of the sequence batch):
Before test A: spring context is initialized.
Before test A: all tables are truncated and all sequences are reset
In test A: sequence numbers 1 to 50 are cached and JaVers uses sequence 1 to 30.
Before test B: all tables are truncated and all sequences are reset
In test B: sequence numbers 31 to 50 are still in the cache. JaVers uses these values and ask the DB for the next batch of sequence numbers, which are again 1 to 50. JaVers uses these values but when it want to store a row in the DB with sequence number 31, an exception occurs since a row with this primary key already exists.