1 16 package scriptella.driver.text; 17 18 import scriptella.AbstractTestCase; 19 import scriptella.configuration.MockConnectionEl; 20 import scriptella.configuration.StringResource; 21 import scriptella.spi.ConnectionParameters; 22 import scriptella.spi.MockDriverContext; 23 import scriptella.spi.MockParametersCallbacks; 24 import scriptella.spi.ParametersCallback; 25 import scriptella.spi.QueryCallback; 26 import scriptella.util.RepeatingInputStream; 27 28 import java.io.ByteArrayOutputStream ; 29 import java.io.InputStream ; 30 import java.io.OutputStream ; 31 import java.io.UnsupportedEncodingException ; 32 import java.net.URL ; 33 import java.util.HashMap ; 34 import java.util.Map ; 35 36 42 public class TextConnectionPerfTest extends AbstractTestCase { 43 private int rows; 44 45 private ByteArrayOutputStream out; 46 47 protected void setUp() throws Exception { 48 super.setUp(); 49 testURLHandler = new TestURLHandler() { 50 byte[] rows = "c1,c2,c3\nc4,c5,c6\n".getBytes(); 51 52 public InputStream getInputStream(final URL u) { 53 return new RepeatingInputStream(rows, 10000); 54 } 55 56 public OutputStream getOutputStream(final URL u) { 57 if (out == null) { 58 out = new ByteArrayOutputStream (); 59 } 60 return out; 61 } 62 63 public int getContentLength(final URL u) { 64 return -1; 65 } 66 }; 67 68 } 69 73 public void testQuery() { 74 Map <String , String > props = new HashMap <String , String >(); 76 ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(props, "tst://file"), MockDriverContext.INSTANCE); 77 78 TextConnection con = new TextConnection(cp); 79 for (int i=0;i<10;i++) { 81 rows = 0; 82 con.executeQuery(new StringResource(".*,(.*2),.*"), MockParametersCallbacks.NULL, new QueryCallback() { 83 public void processRow(final ParametersCallback parameters) { 84 rows++; 85 parameters.getParameter("0"); 86 parameters.getParameter("1"); 87 parameters.getParameter("nosuchcolumn"); 88 89 } 90 }); 91 assertEquals(10000, rows); 92 assertNull("No output should be produced by a query", out); 93 } 94 95 96 } 97 98 103 public void testScript() throws UnsupportedEncodingException { 104 Map <String , String > props = new HashMap <String , String >(); 106 ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(props, "tst://file"), MockDriverContext.INSTANCE); 107 108 TextConnection con = new TextConnection(cp); 109 String expected = "\"*col1*\",\"col2\",\"col3\"\n\"*col21*\",\"col22\",\"col23\"\n"; 110 for (int i = 0; i < 10000; i++) { 111 con.executeScript(new StringResource("\"$col1\",\"col2\",\"col3\"\n\"${col21}\",\"col22\",\"col23\""), 112 MockParametersCallbacks.SIMPLE); 113 out.reset(); 114 } 115 116 con.close(); 117 String actual = out.toString(); assertTrue(actual.indexOf(expected) >= 0); 121 122 123 } 124 125 126 } 127 | Popular Tags |