move method only used in tests to the tests
This commit is contained in:
@@ -54,18 +54,6 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
fileChannel.close();
|
fileChannel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] allocateBlocks(final int numNewBlocks, final int blockSize) throws IOException {
|
|
||||||
|
|
||||||
final long[] result = new long[numNewBlocks];
|
|
||||||
synchronized (fileChannel) {
|
|
||||||
for (int i = 0; i < numNewBlocks; i++) {
|
|
||||||
final long blockOffset = allocateBlock(blockSize);
|
|
||||||
result[i] = blockOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized long allocateBlock(final int blockSize) throws IOException {
|
public synchronized long allocateBlock(final int blockSize) throws IOException {
|
||||||
|
|
||||||
if (blockSize < FREE_LIST_NODE_SIZE) {
|
if (blockSize < FREE_LIST_NODE_SIZE) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class DiskStorageTest {
|
|||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
||||||
final int numBlocks = 10;
|
final int numBlocks = 10;
|
||||||
|
|
||||||
ds.allocateBlocks(numBlocks, BLOCK_SIZE);
|
allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
||||||
final List<DiskBlock> blocks = new ArrayList<>();
|
final List<DiskBlock> blocks = new ArrayList<>();
|
||||||
|
|
||||||
// fill the first 16 512-byte blocks
|
// fill the first 16 512-byte blocks
|
||||||
@@ -101,7 +101,7 @@ public class DiskStorageTest {
|
|||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
||||||
final int numBlocks = 10;
|
final int numBlocks = 10;
|
||||||
|
|
||||||
final long[] blockOffsets = ds.allocateBlocks(numBlocks, BLOCK_SIZE);
|
final long[] blockOffsets = allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
||||||
|
|
||||||
for (final long blockOffset : blockOffsets) {
|
for (final long blockOffset : blockOffsets) {
|
||||||
|
|
||||||
@@ -292,4 +292,15 @@ public class DiskStorageTest {
|
|||||||
buffer[i] = val;
|
buffer[i] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long[] allocateBlocks(final DiskStorage ds, final int numNewBlocks, final int blockSize)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
final long[] result = new long[numNewBlocks];
|
||||||
|
for (int i = 0; i < numNewBlocks; i++) {
|
||||||
|
final long blockOffset = ds.allocateBlock(blockSize);
|
||||||
|
result[i] = blockOffset;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user