|
1 | 1 | package net.sharksystem.aasp; |
2 | 2 |
|
| 3 | +import org.junit.Assert; |
3 | 4 | import org.junit.Test; |
4 | 5 |
|
| 6 | +import java.io.IOException; |
| 7 | +import java.util.Iterator; |
| 8 | + |
5 | 9 | public class ChunkCacheTests { |
| 10 | + public static final String TEST_URI = "TEST_URI"; |
| 11 | + private static final String MESSAGE_ONE = "message one"; |
| 12 | + private static final String MESSAGE_TWO = "message two"; |
| 13 | + |
6 | 14 |
|
7 | 15 | @Test |
8 | | - public void chunkTest1() { |
| 16 | + public void chunkTest1() throws IOException, AASPException { |
| 17 | + |
| 18 | + // open a chunk storage |
| 19 | + AASPStorage storage = AASPEngineFS.getAASPChunkStorage("AASPChunkCacheTest"); |
| 20 | + |
| 21 | + int era = storage.getEra(); |
| 22 | + |
| 23 | + AASPChunkStorage chunkStorage = storage.getChunkStorage(); |
| 24 | + |
| 25 | + AASPChunk chunk = chunkStorage.getChunk(TEST_URI, era); |
| 26 | + |
| 27 | + chunk.add(MESSAGE_ONE); |
| 28 | + |
| 29 | + storage.newEra(); |
| 30 | + |
| 31 | + int newEra = storage.getEra(); |
| 32 | + |
| 33 | + Assert.assertEquals(AASPEngine.nextEra(era), newEra); |
| 34 | + |
| 35 | + chunk = chunkStorage.getChunk(TEST_URI, newEra); |
| 36 | + |
| 37 | + chunk.add(MESSAGE_TWO); |
| 38 | + |
| 39 | + AASPChunkCache aaspChunkCache = chunkStorage.getAASPChunkCache(TEST_URI, era, newEra); |
| 40 | + |
| 41 | + Iterator<CharSequence> messages = aaspChunkCache.getMessages(true); |
| 42 | + |
| 43 | + Assert.assertTrue(messages.hasNext()); |
| 44 | + CharSequence message = messages.next(); |
| 45 | + Assert.assertTrue(message.toString().equalsIgnoreCase(MESSAGE_ONE)); |
| 46 | + |
| 47 | + message = messages.next(); |
| 48 | + Assert.assertTrue(message.toString().equalsIgnoreCase(MESSAGE_TWO)); |
9 | 49 |
|
10 | 50 | } |
11 | 51 | } |
0 commit comments