@Test public void testCanSavePlayerWithoutUnloading() throws Exception { esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); assertTrue(character.isActive()); } }
@Test public void testStoreAndRestoreChunkStore() { Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager, extraDataManager); chunk.setBlock(0, 0, 0, testBlock); chunk.markReady(); ChunkProvider chunkProvider = mock(ChunkProvider.class); when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk)); CoreRegistry.put(ChunkProvider.class, chunkProvider); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); ChunkStore restored = esm.loadChunkStore(CHUNK_POS); assertNotNull(restored); assertEquals(CHUNK_POS, restored.getChunkPosition()); assertNotNull(restored.getChunk()); assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0)); }
@Test public void testGlobalEntitiesStoredAndRestored() throws Exception { EntityRef entity = entityManager.create(new StringComponent("Test")); long entityId = entity.getId(); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); EntitySystemSetupUtil.addReflectionBasedLibraries(context); EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); EngineEntityManager newEntityManager = context.get(EngineEntityManager.class); StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus); newSM.loadGlobalStore(); List<EntityRef> entities = Lists.newArrayList(newEntityManager.getEntitiesWith(StringComponent.class)); assertEquals(1, entities.size()); assertEquals(entityId, entities.get(0).getId()); }
@Test public void testCharacterSurvivesStorage() { esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); PlayerStore restored = esm.loadPlayerStore(PLAYER_ID); restored.restoreEntities(); assertTrue(restored.hasCharacter()); assertEquals(character, restored.getCharacter()); }
@Test public void testPlayerRelevanceLocationSurvivesStorage() { Vector3f loc = new Vector3f(1, 2, 3); character.addComponent(new LocationComponent(loc)); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); PlayerStore restored = esm.loadPlayerStore(PLAYER_ID); assertEquals(loc, restored.getRelevanceLocation()); }
@Test public void testStoreAndRestoreOfPlayerWithoutCharacter() { // remove character from player: character.destroy(); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); PlayerStore restoredStore = esm.loadPlayerStore(PLAYER_ID); assertNotNull(restoredStore); assertFalse(restoredStore.hasCharacter()); assertEquals(new Vector3f(), restoredStore.getRelevanceLocation()); }
@Test public void testChunkSurvivesStorageSaveAndRestore() throws Exception { Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager, extraDataManager); chunk.setBlock(0, 0, 0, testBlock); chunk.setBlock(0, 4, 2, testBlock2); chunk.markReady(); ChunkProvider chunkProvider = mock(ChunkProvider.class); when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk)); when(chunkProvider.getChunk(Matchers.any(Vector3i.class))).thenReturn(chunk); CoreRegistry.put(ChunkProvider.class, chunkProvider); boolean storeChunkInZips = true; esm.setStoreChunksInZips(storeChunkInZips); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); EntitySystemSetupUtil.addReflectionBasedLibraries(context); EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); EngineEntityManager newEntityManager = context.get(EngineEntityManager.class); StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, extraDataManager, storeChunkInZips, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus); newSM.loadGlobalStore(); ChunkStore restored = newSM.loadChunkStore(CHUNK_POS); assertNotNull(restored); assertEquals(CHUNK_POS, restored.getChunkPosition()); assertNotNull(restored.getChunk()); assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0)); assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2)); }
locationComponent.setWorldPosition(positionInChunk); entity.addComponent(locationComponent); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown();
@Test public void testReferenceRemainsValidOverStorageRestoral() throws Exception { EntityRef someEntity = entityManager.create(); character.addComponent(new EntityRefComponent(someEntity)); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); EntitySystemSetupUtil.addReflectionBasedLibraries(context); EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); EngineEntityManager newEntityManager = context.get(EngineEntityManager.class); StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus); newSM.loadGlobalStore(); PlayerStore restored = newSM.loadPlayerStore(PLAYER_ID); restored.restoreEntities(); assertTrue(restored.getCharacter().getComponent(EntityRefComponent.class).entityRef.exists()); }