mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
More work on data file split/join, and added a test.
This commit is contained in:
45
src/test/java/org/qortal/test/DataTests.java
Normal file
45
src/test/java/org/qortal/test/DataTests.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.qortal.test;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.storage.DataFile;
|
||||
import org.qortal.test.common.Common;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DataTests extends Common {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws DataException {
|
||||
Common.useDefaultSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitAndJoin() {
|
||||
String dummyDataString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||||
DataFile dataFile = new DataFile(dummyDataString.getBytes());
|
||||
assertTrue(dataFile.exists());
|
||||
assertEquals(62, dataFile.size());
|
||||
assertEquals("3eyjYjturyVe61grRX42bprGr3Cvw6ehTy4iknVnosDj", dataFile.base58Digest());
|
||||
|
||||
// Split into 7 chunks, each 10 bytes long
|
||||
dataFile.split(10);
|
||||
assertEquals(7, dataFile.chunkCount());
|
||||
|
||||
// Delete the original file
|
||||
dataFile.delete();
|
||||
assertFalse(dataFile.exists());
|
||||
assertEquals(0, dataFile.size());
|
||||
|
||||
// Now rebuild the original file from the chunks
|
||||
assertEquals(7, dataFile.chunkCount());
|
||||
dataFile.join();
|
||||
|
||||
// Validate that the original file is intact
|
||||
assertTrue(dataFile.exists());
|
||||
assertEquals(62, dataFile.size());
|
||||
assertEquals("3eyjYjturyVe61grRX42bprGr3Cvw6ehTy4iknVnosDj", dataFile.base58Digest());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user