public class ReaderToUTF8StreamTest extends BaseTestCase
Explicit tests for the mark/reset feature start with "testMark".
Modifier and Type | Class and Description |
---|---|
private class |
ReaderToUTF8StreamTest.StreamUtil
Utility class executing a few selected method calls on two streams,
expecting both of them to behave in the same way.
|
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_INTERNAL_BUFFER_SIZE
The default size of the internal buffer in ReaderToUTF8Stream.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
ReaderToUTF8StreamTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private void |
checkBeginningOfStream(java.io.InputStream is)
Checks the beginning of the stream, which is expected to consist of five
header bytes (skipped) followed by the bytes for the characters 'a' and
'b'.
|
private void |
fillArray(java.io.InputStream is,
byte[] b)
Fills the array by reading from the stream.
|
private int |
getRandomLength(int currentPos,
int length,
java.util.Random rng)
Returns a random length within the limits.
|
private int |
getRandomLength(int currentPos,
int length,
java.util.Random rng,
boolean reducedSize)
Returns a random length within the limits.
|
private java.io.InputStream |
getStream(int length)
Returns a stream to test, loaded with the repeating modern latin
lowercase alphabet.
|
private void |
mytrace(java.lang.String str)
Trace only if both trace and verbose is true in the test configuration.
|
static junit.framework.Test |
suite() |
void |
testHeaderPresentInStream_Internal()
Makes sure that the header bytes are copied when creating a new buffer
to hold all the required bytes when the stream has been marked.
|
void |
testMarkReadAlmostUntilEOF()
Marks the stream with a read ahead limit larger than the stream itself,
then reads until just before the end of the stream.
|
void |
testMarkReadUntilEOF()
Marks the stream with a read ahead limit larger than the stream itself,
then reads until the end of the stream.
|
void |
testMarkReset1()
Tests mark/reset functionality by comparing with
ByteArrayInputStream . |
void |
testMarkReset2_Internal()
Tests mark/reset functionality by comparing with
ByteArrayInputStream . |
void |
testMarkResetExceedReadAheadLimitFail_Internal()
Tests that the reset-call will fail we exceed the mark ahead limit and
the internal buffer has to be refilled.
|
void |
testMarkResetExceedReadAheadLimitOK_Internal()
Tests an implementation specific feature of ReaderToUTF8Stream, which is
that the mark isn't invalidated even though we read past the read ahead
limit, given that the internal buffer doesn't have to be refilled.
|
void |
testMarkResetOverflowInternalBufferKeepBytes()
Reads almost enough bytes to read past the read ahead limit, then tests
that the reset works.
|
void |
testMarkResetShiftBytesFew_Internal()
Tests that shifting of existing bytes works.
|
void |
testMarkResetShiftBytesMany_Internal()
Tests that shifting of existing bytes works.
|
void |
testMarkResetSimplePosNonZero()
Tests a very basic use of the mark/reset mechanism.
|
void |
testMarkResetSimplePosZero()
Tests a very basic use of the mark/reset mechanism.
|
void |
testRandomSequence()
Performs a series of random operations on a
ReaderToUTF8Stream ,
consisting of read, skip, mark, reset and a noop. |
private void |
testRandomSequence(long seed)
Performs a series of random operations on a
ReaderToUTF8Stream ,
consisting of read, skip, mark, reset and a noop. |
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runBare, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, tearDown, toString
private static int DEFAULT_INTERNAL_BUFFER_SIZE
public static junit.framework.Test suite()
public void testMarkResetSimplePosZero() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkResetSimplePosNonZero() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkResetShiftBytesFew_Internal() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkResetShiftBytesMany_Internal() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkResetExceedReadAheadLimitOK_Internal() throws java.io.IOException
WARNING:This implementation specific feature should not be relied on by the production code! It may change at any time.
java.io.IOException
- if something goes wrongpublic void testMarkResetExceedReadAheadLimitFail_Internal() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkResetOverflowInternalBufferKeepBytes() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testMarkReadUntilEOF() throws java.io.IOException
The current implementation does not allow the stream to be reset after the last byte in the stream has been read once.
java.io.IOException
- if something goes wrongpublic void testMarkReadAlmostUntilEOF() throws java.io.IOException
java.io.IOException
- if something goes wrongpublic void testHeaderPresentInStream_Internal() throws java.io.IOException
java.io.IOException
- if something goes wrongprivate java.io.InputStream getStream(int length)
length
- the length of the stream in charactersprivate void checkBeginningOfStream(java.io.InputStream is) throws java.io.IOException
is
- the stream to checkjava.io.IOException
- if reading from the stream failsAssertionFailedError
- if the stream content isn't as expectedprivate void fillArray(java.io.InputStream is, byte[] b) throws java.io.IOException
is
- input stream to read fromb
- array to fill with bytes from the streamjava.io.IOException
- if reading from the array fails, or the end of the
stream is reachedpublic void testRandomSequence() throws java.io.IOException
ReaderToUTF8Stream
,
consisting of read, skip, mark, reset and a noop.
Note: Turn on debugging (derby.tests.debug=true) to see some information, turn on tracing (derby.tests.trace=true) in addition to see a lot more information.
If the test fails, the seed will be reported in the error message, and the load that failed can be rerun.
java.io.IOException
- if the test failsprivate void testRandomSequence(long seed) throws java.io.IOException
ReaderToUTF8Stream
,
consisting of read, skip, mark, reset and a noop.
Note that this test verifies that executing the operations don't fail, but it doesn't verify that the bytes obtained from the stream are the correct ones.
seed
- seed controlling the test loadjava.io.IOException
- if the test failsprivate int getRandomLength(int currentPos, int length, java.util.Random rng)
This call will operate in the full range of the remaining bytes.
currentPos
- the current position of the streamlength
- the length of the streamrng
- random generatorprivate int getRandomLength(int currentPos, int length, java.util.Random rng, boolean reducedSize)
currentPos
- the current position of the streamlength
- the length of the streamrng
- random generatorreducedSize
- whether to return smaller number or not
(setting to true may increase the number of operations that will be
performed on a stream before it is exhausted)private void mytrace(java.lang.String str)
str
- the string to printpublic void testMarkReset1() throws java.io.IOException
ByteArrayInputStream
.java.io.IOException
- if the test failspublic void testMarkReset2_Internal() throws java.io.IOException
ByteArrayInputStream
. This test relies on knowing the size of
the internal buffer to force a shifting of existing bytes to take place.java.io.IOException
- if the test failsApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.