public TestControlledFrameWriter(int initialFrameSize, boolean deepCopyInputFrames) { super(new CountAnswer(), new CountAnswer(), new CountAnswer(), new CountAnswer(), new CountAnswer(), deepCopyInputFrames); this.initialFrameSize = initialFrameSize; }
public int flushCount() { return flushAnswer.getCallCount(); }
@Override public void close() throws HyracksDataException { delay(closeDuration); closeAnswer.call(); }
@Override public void open() throws HyracksDataException { delay(openDuration); openAnswer.call(); }
public int nextFrameCount() { return nextAnswer.getCallCount(); }
@Override public void flush() throws HyracksDataException { delay(flushDuration); flushAnswer.call(); }
public static CountAnswer createAnswer(FrameWriterOperation operation, Collection<FrameWriterOperation> exceptionThrowingOperations, Collection<FrameWriterOperation> errorThrowingOperations) { if (exceptionThrowingOperations.contains(operation)) { return new CountAndThrowException(EXCEPTION_MESSAGE + operation.toString()); } else if (exceptionThrowingOperations.contains(operation)) { return new CountAndThrowError(ERROR_MESSAGE + operation.toString()); } else { return new CountAnswer(); } }
public int closeCount() { return closeAnswer.getCallCount(); }
@Override public void fail() throws HyracksDataException { delay(failDuration); failAnswer.call(); }
public int failCount() { return failAnswer.getCallCount(); }
@Override public void nextFrame(ByteBuffer buffer) throws HyracksDataException { if (deepCopyFrames) { if (lastFrame.capacity() != buffer.capacity()) { lastFrame = ByteBuffer.allocate(buffer.capacity()); } lastFrame.clear(); lastFrame.put(buffer.array()); } else { lastFrame = buffer; } delay(nextDuration); nextAnswer.call(); }
public int openCount() { return openAnswer.getCallCount(); }
public synchronized boolean validate(boolean finished) { if (failAnswer.getCallCount() > 1 || closeAnswer.getCallCount() > 1 || openAnswer.getCallCount() > 1) { return false; } if (openAnswer.getCallCount() == 0 && (nextAnswer.getCallCount() > 0 || failAnswer.getCallCount() > 0 || closeAnswer.getCallCount() > 0)) { return false; } if (finished) { if (closeAnswer.getCallCount() == 0 && (nextAnswer.getCallCount() > 0 || failAnswer.getCallCount() > 0 || openAnswer.getCallCount() > 0)) { return false; } } return true; }