public static TestFrameWriter create(Collection<FrameWriterOperation> exceptionThrowingOperations, Collection<FrameWriterOperation> errorThrowingOperations, boolean deepCopyInputFrames) { CountAnswer openAnswer = createAnswer(FrameWriterOperation.Open, exceptionThrowingOperations, errorThrowingOperations); CountAnswer nextAnswer = createAnswer(FrameWriterOperation.NextFrame, exceptionThrowingOperations, errorThrowingOperations); CountAnswer flushAnswer = createAnswer(FrameWriterOperation.Flush, exceptionThrowingOperations, errorThrowingOperations); CountAnswer failAnswer = createAnswer(FrameWriterOperation.Fail, exceptionThrowingOperations, errorThrowingOperations); CountAnswer closeAnswer = createAnswer(FrameWriterOperation.Close, exceptionThrowingOperations, errorThrowingOperations); return new TestFrameWriter(openAnswer, nextAnswer, flushAnswer, failAnswer, closeAnswer, deepCopyInputFrames); }
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 static TestFrameWriter create() { return create(Collections.emptyList(), Collections.emptyList(), false); }
public static TestTupleCounterFrameWriter create(RecordDescriptor recordDescriptor, Collection<FrameWriterOperation> exceptionThrowingOperations, Collection<FrameWriterOperation> errorThrowingOperations, boolean deepCopyInputFrames) { CountAnswer openAnswer = FrameWriterTestUtils.createAnswer(FrameWriterOperation.Open, exceptionThrowingOperations, errorThrowingOperations); CountAnswer nextAnswer = FrameWriterTestUtils.createAnswer(FrameWriterOperation.NextFrame, exceptionThrowingOperations, errorThrowingOperations); CountAnswer flushAnswer = FrameWriterTestUtils.createAnswer(FrameWriterOperation.Flush, exceptionThrowingOperations, errorThrowingOperations); CountAnswer failAnswer = FrameWriterTestUtils.createAnswer(FrameWriterOperation.Fail, exceptionThrowingOperations, errorThrowingOperations); CountAnswer closeAnswer = FrameWriterTestUtils.createAnswer(FrameWriterOperation.Close, exceptionThrowingOperations, errorThrowingOperations); return new TestTupleCounterFrameWriter(recordDescriptor, openAnswer, nextAnswer, flushAnswer, failAnswer, closeAnswer, deepCopyInputFrames); }
public int openCount() { return openAnswer.getCallCount(); }
@Override public void nextFrame(ByteBuffer buffer) throws HyracksDataException { super.nextFrame(buffer); accessor.reset(buffer); count += accessor.getTupleCount(); }
public TestControlledFrameWriter(int initialFrameSize, boolean deepCopyInputFrames) { super(new CountAnswer(), new CountAnswer(), new CountAnswer(), new CountAnswer(), new CountAnswer(), deepCopyInputFrames); this.initialFrameSize = initialFrameSize; }
public static TestControlledFrameWriter create(int initialFrameSize, boolean deepCopyInputFrames) { return new TestControlledFrameWriter(initialFrameSize, deepCopyInputFrames); } }
@Override public IFrameWriter createFrameWriter(int receiverIndex) throws HyracksDataException { // The created writers must retain a deep copy of the input frame writers.put(receiverIndex, FrameWriterTestUtils.create(Collections.emptyList(), Collections.emptyList(), true)); return writers.get(receiverIndex); }
public int failCount() { return failAnswer.getCallCount(); }
public int flushCount() { return flushAnswer.getCallCount(); }
public int nextFrameCount() { return nextAnswer.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 closeCount() { return closeAnswer.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; }