assertEquals(originalLastBlock.length, truncated.length); assertTrue(Arrays.equals(originalLastBlock, truncated)); assertTrue(storage.getStatus() == Status.ENCODED);
public void testSmallSplitfileCompletion() throws IOException, InsertException, MissingKeyException { Random r = new Random(12121); long size = 65536; // Exact multiple, so no last block LockableRandomAccessBuffer data = generateData(r, size); HashResult[] hashes = getHashes(data); MyCallback cb = new MyCallback(); InsertContext context = baseContext.clone(); KeysFetchingLocally keys = new MyKeysFetchingLocally(); SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null, new ClientMetadata(), false, null, smallRAFFactory, false, context, cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker, r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0); storage.start(); cb.waitForFinishedEncode(); assertEquals(storage.segments.length, 1); SplitFileInserterSegmentStorage segment = storage.segments[0]; assertEquals(segment.dataBlockCount, 2); assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertEquals(storage.getStatus(), Status.ENCODED); for(int i=0;i<segment.totalBlockCount;i++) { segment.onInsertedBlock(i, segment.encodeBlock(i).getClientKey()); } cb.waitForSucceededInsert(); assertEquals(storage.getStatus(), Status.SUCCEEDED); }
public void testCancel() throws IOException, InsertException, MissingKeyException { Random r = new Random(12124); long size = 32768*6; BarrierRandomAccessBuffer data = new BarrierRandomAccessBuffer(generateData(r, size)); HashResult[] hashes = getHashes(data); data.pause(); MyCallback cb = new MyCallback(); InsertContext context = baseContext.clone(); context.earlyEncode = true; KeysFetchingLocally keys = new MyKeysFetchingLocally(); SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null, new ClientMetadata(), false, null, smallRAFFactory, false, context, cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker, r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0); storage.start(); assertEquals(storage.getStatus(), Status.STARTED); assertEquals(storage.segments.length, 1); SplitFileInserterSegmentStorage segment = storage.segments[0]; segment.onFailure(0, new InsertException(InsertExceptionMode.INTERNAL_ERROR)); data.proceed(); // Now it will complete encoding, and then report in, and then fail. try { cb.waitForFinishedEncode(); assertFalse(true); // Should have failed. } catch (InsertException e) { assertFalse(segment.isEncoding()); assertEquals(storage.getStatus(), Status.FAILED); } }
public void testSmallSplitfileNoLastBlock() throws IOException, InsertException { Random r = new Random(12121); long size = 65536; // Exact multiple, so no last block LockableRandomAccessBuffer data = generateData(r, size); HashResult[] hashes = getHashes(data); MyCallback cb = new MyCallback(); KeysFetchingLocally keys = new MyKeysFetchingLocally(); SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null, new ClientMetadata(), false, null, smallRAFFactory, false, baseContext.clone(), cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker, r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0); storage.start(); cb.waitForFinishedEncode(); assertEquals(storage.segments.length, 1); assertEquals(storage.segments[0].dataBlockCount, 2); assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); assertTrue(storage.getStatus() == Status.ENCODED); }
assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); assertTrue(storage.getStatus() == Status.ENCODED); executor.waitForIdle(); SplitFileInserterStorage resumed = new SplitFileInserterStorage(storage.getRAF(), data, cb, r, assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertTrue(resumed.getStatus() == Status.ENCODED); for(int i=0;i<segment.totalBlockCount;i++) { segment.onInsertedBlock(i, segment.encodeBlock(i).getClientKey()); assertEquals(Status.SUCCEEDED, resumed.getStatus());
assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); assertTrue(storage.getStatus() == Status.ENCODED); SplitFileInserterStorage resumed = null; for(int i=0;i<storage.segments[0].totalBlockCount;i++) { assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertTrue(resumed.getStatus() == Status.ENCODED); segment.onInsertedBlock(i, segment.encodeBlock(i).getClientKey()); assertEquals(Status.SUCCEEDED, resumed.getStatus());
assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); assertTrue(storage.getStatus() == Status.ENCODED); SplitFileInserterStorage resumed = null; for(int i=0;i<storage.segments[0].totalBlockCount;i++) { assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertTrue(resumed.getStatus() == Status.ENCODED); segment.onInsertedBlock(i, segment.encodeBlock(i).getClientKey()); assertEquals(Status.SUCCEEDED, resumed.getStatus());
assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); assertTrue(storage.getStatus() == Status.ENCODED); SplitFileInserterStorage resumed = null; assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertTrue(resumed.getStatus() == Status.ENCODED); segment.onFailure(0, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(3, e.errorCodes.getErrorCount(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(e.errorCodes.totalCount(), 3); assertEquals(Status.FAILED, resumed.getStatus()); assertEquals(Status.FAILED, resumed.getStatus());
assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertEquals(storage.getStatus(), Status.ENCODED); segment.setKey(0, segment.encodeBlock(0).getClientKey()); segment.onFailure(0, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(storage.getStatus(), Status.ENCODED); segment.onFailure(0, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(storage.getStatus(), Status.ENCODED); segment.onFailure(0, new InsertException(InsertExceptionMode.REJECTED_OVERLOAD)); assertEquals(e.errorCodes.getErrorCount(InsertExceptionMode.REJECTED_OVERLOAD), 1); assertEquals(e.errorCodes.totalCount(), 3); assertEquals(storage.getStatus(), Status.FAILED);
assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertEquals(storage.getStatus(), Status.ENCODED); for(int i=0;i<3;i++) { segment.onFailure(0, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(e.errorCodes.getErrorCount(InsertExceptionMode.ROUTE_NOT_FOUND), 3); assertEquals(e.errorCodes.totalCount(), 3); assertEquals(storage.getStatus(), Status.FAILED);
public void testSmallSplitfileHasKeys() throws IOException, InsertException, MissingKeyException { Random r = new Random(12121); long size = 65536; // Exact multiple, so no last block LockableRandomAccessBuffer data = generateData(r, size); HashResult[] hashes = getHashes(data); MyCallback cb = new MyCallback(); InsertContext context = baseContext.clone(); context.earlyEncode = true; KeysFetchingLocally keys = new MyKeysFetchingLocally(); SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null, new ClientMetadata(), false, null, smallRAFFactory, false, context, cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker, r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0); storage.start(); cb.waitForFinishedEncode(); assertEquals(storage.segments.length, 1); assertEquals(storage.segments[0].dataBlockCount, 2); assertEquals(storage.segments[0].checkBlockCount, 3); assertEquals(storage.segments[0].crossCheckBlockCount, 0); cb.waitForHasKeys(); for(int i=0;i<storage.segments[0].dataBlockCount+storage.segments[0].checkBlockCount+storage.segments[0].crossCheckBlockCount;i++) storage.segments[0].readKey(i); storage.encodeMetadata(); assertTrue(storage.getStatus() == Status.ENCODED); }
assertEquals(segment.checkBlockCount, 3); assertEquals(segment.crossCheckBlockCount, 0); assertEquals(storage.getStatus(), Status.ENCODED); assertTrue(InsertException.isFatal(InsertExceptionMode.INTERNAL_ERROR)); segment.onFailure(0, new InsertException(InsertExceptionMode.INTERNAL_ERROR)); assertEquals(e.errorCodes.getErrorCount(InsertExceptionMode.INTERNAL_ERROR), 1); assertEquals(e.errorCodes.totalCount(), 1); assertEquals(storage.getStatus(), Status.FAILED);
private void testEncodeAfterShutdownCrossSegment(long size) throws InsertException, IOException, MissingKeyException, StorageFormatException, ChecksumFailedException, ResumeFailedException, MetadataUnresolvedException { Random r = new Random(12121); LockableRandomAccessBuffer data = generateData(r, size); HashResult[] hashes = getHashes(data); MyCallback cb = new MyCallback(); MyKeysFetchingLocally keys = new MyKeysFetchingLocally(); SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null, new ClientMetadata(), false, null, smallRAFFactory, true, baseContext.clone(), cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker, r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0); executor.waitForIdle(); // Has not encoded anything. for(SplitFileInserterSegmentStorage segment : storage.segments) assert(!segment.isFinishedEncoding()); SplitFileInserterStorage resumed = new SplitFileInserterStorage(storage.getRAF(), data, cb, r, memoryLimitedJobRunner, jobRunner, ticker, keys, fg, persistentFileTracker, null); resumed.start(); cb.waitForFinishedEncode(); cb.waitForHasKeys(); executor.waitForIdle(); resumed.encodeMetadata(); assertTrue(resumed.getStatus() == Status.ENCODED); resumed.originalData.free(); resumed.getRAF().free(); }
assertTrue(storage.getStatus() == Status.ENCODED);