use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.
the class PositionedStoreStreamTest method testSimpleReadSequence.
/**
* Executes a simple read sequence against the lower case modern latin
* alphabet, which involves some repositioning.
*/
public void testSimpleReadSequence() throws IOException, StandardException {
InputStream in = new LoopingAlphabetStream(26);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals('a', pss.read());
pss.reposition(9);
assertEquals('j', pss.read());
pss.reposition(10);
assertEquals('k', pss.read());
pss.reposition(9);
assertEquals('j', pss.read());
pss.reposition(25);
assertEquals('z', pss.read());
assertEquals(-1, pss.read());
pss.reposition(1);
assertEquals('b', pss.read());
pss.reposition(1);
assertEquals('b', pss.read());
}
use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.
the class PositionedStoreStreamTest method testPositionAfterEOFReadArray.
/**
* Verifies that reading after EOF doesn't change the position.
*/
public void testPositionAfterEOFReadArray() throws IOException, StandardException {
InputStream in = new LoopingAlphabetStream(10);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals(0, pss.getPosition());
byte[] two = new byte[2];
for (int i = 0; i < 10; i += 2) {
assertEquals(2, pss.read(two, 0, 2));
assertEquals(i + 2, pss.getPosition());
}
assertEquals(10, pss.getPosition());
assertEquals(-1, pss.read(two, 0, 2));
assertEquals(10, pss.getPosition());
assertEquals(-1, pss.read(two, 0, 2));
assertEquals(0, pss.skip(21));
assertEquals(-1, pss.read());
assertEquals(10, pss.getPosition());
pss.resetStream();
assertEquals(0, pss.getPosition());
}
use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.
the class PositionedStoreStreamTest method testRepositionForwards.
public void testRepositionForwards() throws IOException, StandardException {
final long length = 20L;
InputStream in = new LoopingAlphabetStream(length);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals(0, pss.getPosition());
// Position forwards one by one.
for (int i = 0; i < length; i++) {
InputStream inComp = new LoopingAlphabetStream(length);
pss.reposition(i);
inComp.skip(i);
assertEquals(inComp.read(), pss.read());
}
// Position forwards two by two.
for (int i = 1; i < length; i += 2) {
InputStream inComp = new LoopingAlphabetStream(length);
pss.reposition(i);
inComp.skip(i);
assertEquals(inComp.read(), pss.read());
}
}
use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.
the class LobLengthTest method testLongLobLengths.
/**
* There was a defect (DERBY-121) where the server and client
* were processing lob lengths incorrectly. For lob lengths
* that are represented by 24 or more bits, the server and
* Derby client were doing incorrect bit-shifting. This
* test makes sure that problem no longer occurs.
*/
public void testLongLobLengths() throws Exception {
PreparedStatement pSt = prepareStatement("insert into lobTable100M(bl) values (?)");
// The error we're testing occurs when the server
// is shifting bits 24 and higher of the lob's
// length (in bytes). This means that, in order
// to check for the error, we have to specify a
// lob length (in bytes) that requires at least
// 24 bits to represent. Thus for a blob the
// length of the test data must be specified as
// at least 2^24 bytes (hence the '16800000' in
// the next line).
int lobSize = 16800000;
pSt.setBinaryStream(1, new LoopingAlphabetStream(lobSize), lobSize);
// Now try the insert; this is where the server processes
// the lob length.
pSt.execute();
pSt.close();
}
use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.
the class LobStreamsTest method testClobAsciiWrite1Param.
/**
* Tests the ClobOutputStream.write(int b) method
*/
public void testClobAsciiWrite1Param() throws Exception {
InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);
PreparedStatement stmt3 = prepareStatement("SELECT c FROM testBlobX1 WHERE a = 1");
ResultSet rs3 = stmt3.executeQuery();
rs3.next();
Clob clob = rs3.getClob(1);
assertTrue("FAIL -- clob is NULL", clob != null);
int buffer;
OutputStream outstream = clob.setAsciiStream(1L);
while ((buffer = streamIn.read()) != -1) {
outstream.write(buffer);
}
outstream.close();
streamIn.close();
PreparedStatement stmt4 = prepareStatement("UPDATE testBlobX1 SET c = ? WHERE a = 1");
stmt4.setClob(1, clob);
stmt4.executeUpdate();
stmt4.close();
rs3.close();
rs3 = stmt3.executeQuery();
assertTrue("FAIL -- clob not found", rs3.next());
clob = rs3.getClob(1);
long new_length = clob.length();
assertEquals("FAIL -- wrong clob length", streamSize[1], new_length);
// Check contents ...
InputStream fStream = new LoopingAlphabetStream(streamSize[1]);
InputStream lStream = clob.getAsciiStream();
assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream));
fStream.close();
lStream.close();
rs3.close();
stmt3.close();
}
Aggregations