Search in sources :

Example 6 with KettleEOFException

use of org.pentaho.di.core.exception.KettleEOFException in project pentaho-kettle by pentaho.

the class DBCacheEntryTest method testClass.

@Test
public void testClass() throws IOException, KettleFileException {
    final String dbName = "dbName";
    final String sql = "sql query";
    DBCacheEntry entry = new DBCacheEntry(dbName, sql);
    assertTrue(entry.sameDB("dbName"));
    assertFalse(entry.sameDB("otherDb"));
    assertEquals(dbName.toLowerCase().hashCode() ^ sql.toLowerCase().hashCode(), entry.hashCode());
    DBCacheEntry otherEntry = new DBCacheEntry();
    assertFalse(otherEntry.sameDB("otherDb"));
    assertEquals(0, otherEntry.hashCode());
    assertFalse(entry.equals(otherEntry));
    assertFalse(entry.equals(new Object()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(dbName);
    dos.writeUTF(sql);
    byte[] bytes = baos.toByteArray();
    InputStream is = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(is);
    DBCacheEntry disEntry = new DBCacheEntry(dis);
    assertTrue(disEntry.equals(entry));
    try {
        new DBCacheEntry(dis);
        fail("Should throw KettleEOFException on EOFException");
    } catch (KettleEOFException keofe) {
    // Ignore
    }
    baos.reset();
    assertTrue(disEntry.write(dos));
    assertArrayEquals(bytes, baos.toByteArray());
}
Also used : KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)6 IOException (java.io.IOException)4 DataInputStream (java.io.DataInputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3 KettleException (org.pentaho.di.core.exception.KettleException)3 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3 BufferedInputStream (java.io.BufferedInputStream)2 DataOutputStream (java.io.DataOutputStream)2 EOFException (java.io.EOFException)2 InputStream (java.io.InputStream)2 Socket (java.net.Socket)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 InvalidKeyException (java.security.InvalidKeyException)1 Key (java.security.Key)1