Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawomir Chodnicki committed Feb 21, 2011
1 parent c3c675b commit 3827bcb
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,4 +3,5 @@ bin
dist dist
testdist testdist
testclasses testclasses
package
.DS_Store .DS_Store
22 changes: 8 additions & 14 deletions build.xml
Expand Up @@ -27,7 +27,7 @@
<property name="package" location="package" /> <property name="package" location="package" />
<property name="pluginname" value="Ruby" /> <property name="pluginname" value="Ruby" />
<property name="jarfilename" value="ruby-step.jar" /> <property name="jarfilename" value="ruby-step.jar" />
<property name="zipfilename" value="${pluginname}Plugin_Kettle_4.0.zip" /> <property name="zipfilename" value="${pluginname}Plugin_Kettle_4.zip" />


<!-- used for running the tests --> <!-- used for running the tests -->
<path id="test.classpath"> <path id="test.classpath">
Expand Down Expand Up @@ -155,19 +155,13 @@
<delete dir="${package}" /> <delete dir="${package}" />
<mkdir dir="${package}" /> <mkdir dir="${package}" />
<mkdir dir="${package}/Sources" /> <mkdir dir="${package}/Sources" />
<mkdir dir="${package}/Samples" />
<mkdir dir="${package}/${pluginname}" /> <mkdir dir="${package}/${pluginname}" />


<!-- copy plugin --> <!-- copy plugin -->
<copy todir="${package}/${pluginname}"> <copy todir="${package}/${pluginname}">
<fileset dir="${dist}" includes="**/*.*" /> <fileset dir="${dist}" includes="**/*.*" />
</copy> </copy>


<!-- copy samples -->
<copy todir="${package}/Samples">
<fileset dir="samples" includes="**/*.*" />
</copy>

<!-- prepare sources --> <!-- prepare sources -->
<copy todir="${package}/Sources/plugin"> <copy todir="${package}/Sources/plugin">
<fileset dir="plugin" includes="**/*.*" /> <fileset dir="plugin" includes="**/*.*" />
Expand All @@ -179,18 +173,18 @@
<copy todir="${package}/Sources/lib"> <copy todir="${package}/Sources/lib">
<fileset dir="lib" includes="**/*.*" /> <fileset dir="lib" includes="**/*.*" />
</copy> </copy>
<copy todir="${package}/Sources/build"> <copy todir="${package}/Sources">
<fileset dir="build" includes="**/build.xml" /> <fileset dir="." includes="build.xml" />
<fileset dir="." includes="build.properties" />
</copy> </copy>


<!-- zip up the contents --> <!-- zip up the contents -->
<delete file="${package}/${zipfilename}" /> <delete file="${package}/${zipfilename}" />
<zip destfile="${package}/${zipfilename}"> <zip destfile="${package}/${zipfilename}">
<zipfileset dir="${package}/${pluginname}" prefix="${pluginname}" /> <zipfileset dir="${package}/${pluginname}" prefix="${pluginname}" />
<zipfileset dir="${package}/Sources" prefix="Sources" /> <zipfileset dir="${package}/Sources" prefix="Sources" />
<zipfileset dir="${package}/Samples" prefix="Samples" /> <zipfileset dir="." includes="INSTALLATION.txt" />
<zipfileset dir="build" includes="INSTALLATION.txt" /> <zipfileset dir="." includes="LICENSE.txt" />
<zipfileset dir="build" includes="LICENSE.txt" />
</zip> </zip>


</target> </target>
Expand All @@ -206,14 +200,14 @@
<target name="test-compile" depends="init" description="compile the test sources"> <target name="test-compile" depends="init" description="compile the test sources">
<mkdir dir="${testclasses}" /> <mkdir dir="${testclasses}" />
<javac target="1.6" srcdir="${testsrc}" destdir="${testclasses}" debuglevel="lines,vars,source" debug="true"> <javac target="1.6" srcdir="${testsrc}" destdir="${testclasses}" debuglevel="lines,vars,source" debug="true">
<classpath refid="compile.classpath" /> <classpath refid="test.classpath" />
</javac> </javac>
</target> </target>




<target name="test" depends="test-compile,test-dist"> <target name="test" depends="test-compile,test-dist">
<junit fork="yes" haltonfailure="yes" maxmemory="256m"> <junit fork="yes" haltonfailure="yes" maxmemory="256m">
<test name="org.typeexit.kettle.plugin.steps.ruby.TestSamples" /> <test name="org.typeexit.kettle.plugin.steps.ruby.TestSuite" />
<formatter type="plain" usefile="false" /> <formatter type="plain" usefile="false" />
<classpath refid="test.classpath" /> <classpath refid="test.classpath" />
</junit> </junit>
Expand Down
76 changes: 39 additions & 37 deletions plugin/samples/20 - Calling Java/Scripting JDBC.ktr
Expand Up @@ -73,7 +73,7 @@
<server/> <server/>
<type>H2</type> <type>H2</type>
<access>Native</access> <access>Native</access>
<database>mem:MyDatabase;DB_CLOSE_DELAY=-1</database> <database>mem:MyDatabase;DB_CLOSE_DELAY=-1;MULTI_THREADED=0</database>
<port>8082</port> <port>8082</port>
<username>H2</username> <username>H2</username>
<password>Encrypted </password> <password>Encrypted </password>
Expand Down Expand Up @@ -192,6 +192,7 @@ while result.next do
end end


# close the db connection # close the db connection
result.close
conn.close conn.close
</body> </body>
<role>ROW_SCRIPT</role> <role>ROW_SCRIPT</role>
Expand Down Expand Up @@ -227,24 +228,6 @@ conn.close
</GUI> </GUI>
</step> </step>


<step>
<name>output critters</name>
<type>Dummy</type>
<description/>
<distribute>Y</distribute>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>422</xloc>
<yloc>154</yloc>
<draw>Y</draw>
</GUI>
</step>

<step> <step>
<name>Read function info about in-memory H2 DB</name> <name>Read function info about in-memory H2 DB</name>
<type>TypeExitRubyStep</type> <type>TypeExitRubyStep</type>
Expand Down Expand Up @@ -347,24 +330,6 @@ end</body>
</GUI> </GUI>
</step> </step>


<step>
<name>output function info</name>
<type>Dummy</type>
<description/>
<distribute>Y</distribute>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>423</xloc>
<yloc>267</yloc>
<draw>Y</draw>
</GUI>
</step>

<step> <step>
<name>Read supported data types from in-memory H2 DB</name> <name>Read supported data types from in-memory H2 DB</name>
<type>TypeExitRubyStep</type> <type>TypeExitRubyStep</type>
Expand Down Expand Up @@ -416,6 +381,7 @@ while rs.next do
end end


# close the db connection # close the db connection
rs.close
conn.close conn.close
</body> </body>
<role>ROW_SCRIPT</role> <role>ROW_SCRIPT</role>
Expand Down Expand Up @@ -523,6 +489,24 @@ end</body>
</GUI> </GUI>
</step> </step>


<step>
<name>output critters</name>
<type>Dummy</type>
<description/>
<distribute>Y</distribute>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>422</xloc>
<yloc>154</yloc>
<draw>Y</draw>
</GUI>
</step>

<step> <step>
<name>output datatype info</name> <name>output datatype info</name>
<type>Dummy</type> <type>Dummy</type>
Expand All @@ -541,6 +525,24 @@ end</body>
</GUI> </GUI>
</step> </step>


<step>
<name>output function info</name>
<type>Dummy</type>
<description/>
<distribute>Y</distribute>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>423</xloc>
<yloc>267</yloc>
<draw>Y</draw>
</GUI>
</step>

<step_error_handling> <step_error_handling>
</step_error_handling> </step_error_handling>
<slave-step-copy-partition-distribution> <slave-step-copy-partition-distribution>
Expand Down
Expand Up @@ -14,16 +14,12 @@


public class BufferStreamReader { public class BufferStreamReader {


// private BaseStep step;
// private SimpleExecutionModel model;
private RubyStepData data; private RubyStepData data;
private RubyArray buffer; private RubyArray buffer;
private long readPointer; private long readPointer;


public BufferStreamReader(SimpleExecutionModel model, RubyArray buffer) throws KettleStepException{ public BufferStreamReader(SimpleExecutionModel model, RubyArray buffer) throws KettleStepException{


// this.model = model;
// this.step = model.getStep();
this.data = model.getData(); this.data = model.getData();


this.buffer = buffer; this.buffer = buffer;
Expand Down
41 changes: 41 additions & 0 deletions test/org/typeexit/kettle/plugin/steps/ruby/TestFactory.java
@@ -0,0 +1,41 @@
package org.typeexit.kettle.plugin.steps.ruby;

import org.jruby.embed.ScriptingContainer;
import org.typeexit.kettle.plugin.steps.ruby.RubyStepMeta.RubyVersion;

import junit.framework.TestCase;

public class TestFactory extends TestCase{

public void testFactory(){

ScriptingContainer c = RubyStepFactory.createScriptingContainer(false, RubyVersion.RUBY_1_8);
c.runScriptlet("puts \"Ruby version: #{RUBY_VERSION}\"");

}

public void testJDBCDrivers(){
// this is a regression test for JDBC drivers disappearing from the JVM, since jruby will
// remove them by default.
// The factory is supposed to create a container that does not do that

// this script will raise an exception if the org.h2.Driver got unregistered
// see http://jira.codehaus.org/browse/JRUBY-5528
String testScript = "require 'java'" + "\n" +
"Java::org.h2.Driver" + "\n" +
"url = 'jdbc:h2:mem:MyDatabase'" + "\n" +
"conn = java.sql.DriverManager.get_connection(url, 'H2', '')" + "\n" +
"conn.close";

// if the script can be executed repeatedly, all is fine. It raises an exception
// if the driver got unregistered at some point.
for (int i=1;i<=5;i++){
ScriptingContainer c = RubyStepFactory.createScriptingContainer(false, RubyVersion.RUBY_1_8);
c.runScriptlet(testScript);
c.terminate();
System.out.println("Testing JDBC Driver persistence: iteration "+i);
}

}

}
Expand Up @@ -11,7 +11,7 @@


// //
// NOTE: this is a blackbox test that works on distribution files // NOTE: this is a blackbox test that works on distribution files
// It should only be run run after "ant testdist" has put a test distribution into place // It should only be run run after "ant test-dist" has put a test distribution into place
// //
public class TestSamples extends TestCase { public class TestSamples extends TestCase {


Expand Down
10 changes: 10 additions & 0 deletions test/org/typeexit/kettle/plugin/steps/ruby/TestSuite.java
@@ -0,0 +1,10 @@
package org.typeexit.kettle.plugin.steps.ruby;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({ TestFactory.class, TestSamples.class })
public class TestSuite {

}

0 comments on commit 3827bcb

Please sign in to comment.