Project

General

Profile

« Previous | Next » 

Revision 47553

introducing dnet45 version of IIS CDH4 legacy libs

View differences:

modules/icm-iis-core/trunk/pom.xml.disabled
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-hadoop-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<artifactId>icm-iis-core</artifactId>
10
	<packaging>jar</packaging>
11
	<version>1.0.1-SNAPSHOT</version>
12

  
13
	<scm>
14
	  <developerConnection>
15
	    scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/icm-iis-core/trunk
16
	  </developerConnection>
17
	</scm>
18

  
19
	<properties>
20
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21
	</properties>
22
	<dependencies>
23
		<dependency>
24
			<groupId>eu.dnetlib</groupId>
25
			<artifactId>icm-iis-3rdparty-avrojsoncoders</artifactId>
26
			<version>[1.0.0,2.0.0)</version>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.apache.commons</groupId>
30
			<artifactId>commons-lang3</artifactId>
31
			<version>3.1</version>
32
		</dependency>
33
		<dependency>
34
			<groupId>commons-cli</groupId>
35
			<artifactId>commons-cli</artifactId>
36
			<version>1.2</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>org.apache.hadoop</groupId>
40
			<artifactId>hadoop-common</artifactId>
41
			<version>${iis.hadoop.common.version}</version>
42
			<scope>provided</scope>
43
		</dependency>
44
		<dependency>
45
			<groupId>org.apache.hadoop</groupId>
46
			<artifactId>hadoop-common</artifactId>
47
			<version>${iis.hadoop.common.version}</version>
48
			<type>test-jar</type>
49
			<scope>test</scope>
50
		</dependency>
51
		<!-- This is needed by map-reduce-related classes -->
52
		<dependency>
53
			<groupId>org.apache.hadoop</groupId>
54
			<artifactId>hadoop-core</artifactId>
55
			<version>${iis.hadoop.core.version}</version>
56
			<scope>provided</scope>
57
		</dependency>
58
		<dependency>
59
			<groupId>org.apache.hadoop</groupId>
60
			<artifactId>hadoop-hdfs</artifactId>
61
			<version>${iis.hadoop.hdfs.version}</version>
62
			<scope>provided</scope>
63
		</dependency>
64
		<dependency>
65
			<groupId>org.apache.hadoop</groupId>
66
			<artifactId>hadoop-hdfs</artifactId>
67
			<version>${iis.hadoop.hdfs.version}</version>
68
			<type>test-jar</type>
69
			<scope>test</scope>
70
		</dependency>
71
		<dependency>
72
			<groupId>org.apache.hadoop</groupId>
73
			<artifactId>hadoop-test</artifactId>
74
			<version>${iis.hadoop.test.version}</version>
75
			<scope>test</scope>
76
		</dependency>
77
		<dependency>
78
			<groupId>org.apache.oozie</groupId>
79
			<artifactId>oozie-core</artifactId>
80
			<version>${iis.oozie.version}</version>
81
			<scope>provided</scope>
82
		</dependency>
83
		<!-- Needed by Avro { -->
84
		<dependency>
85
			<groupId>org.apache.avro</groupId>
86
			<artifactId>avro</artifactId>
87
			<version>${iis.avro.version}</version>
88
		</dependency>
89
		<dependency>
90
			<groupId>org.apache.avro</groupId>
91
			<artifactId>avro-mapred</artifactId>
92
			<version>${iis.avro.version}</version>
93
			<classifier>hadoop2</classifier>
94
		</dependency>
95
		<!-- Needed by Avro } -->
96
		<!-- Jar containing testing classes that have been missing -->
97
		<dependency>
98
			<groupId>org.apache.oozie</groupId>
99
			<artifactId>oozie-core</artifactId>
100
			<version>${iis.oozie.version}</version>
101
			<type>test-jar</type>
102
			<scope>test</scope>
103
		</dependency>
104
		<dependency>
105
			<groupId>junit</groupId>
106
			<artifactId>junit</artifactId>
107
			<version>4.10</version>
108
			<scope>test</scope>
109
		</dependency>
110
		<dependency>
111
			<groupId>com.google.code.gson</groupId>
112
			<artifactId>gson</artifactId>
113
			<version>2.2.4</version>
114
		</dependency>
115
	</dependencies>
116
	<build>
117
		<plugins>
118
			<!-- Plugin that generates Java classes from Avro schemas -->
119
			<plugin>
120
				<groupId>org.apache.avro</groupId>
121
				<artifactId>avro-maven-plugin</artifactId>
122
				<version>${iis.avro.version}</version>
123
				<executions>
124
					<execution>
125
						<phase>generate-sources</phase>
126
						<goals>
127
							<goal>schema</goal>
128
							<goal>idl-protocol</goal>
129
						</goals>
130
						<configuration>
131
							<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
132
							<outputDirectory>${project.basedir}/target/generated-sources/java/</outputDirectory>
133
						</configuration>
134
					</execution>
135
				</executions>
136
			</plugin>
137
			<!-- This plugin makes the Maven->Update Project Configuration not forget 
138
				about the "target/generated-sources/java" source path -->
139
			<plugin>
140
				<groupId>org.codehaus.mojo</groupId>
141
				<artifactId>build-helper-maven-plugin</artifactId>
142
				<executions>
143
					<execution>
144
						<id>add-source</id>
145
						<phase>generate-sources</phase>
146
						<goals>
147
							<goal>add-source</goal>
148
						</goals>
149
						<configuration>
150
							<sources>
151
								<source>${project.build.directory}/generated-sources/java/</source>
152
							</sources>
153
						</configuration>
154
					</execution>
155
				</executions>
156
			</plugin>
157
			<!-- Plugin that generates jar with test classes -->
158
			<plugin>
159
				<groupId>org.apache.maven.plugins</groupId>
160
				<artifactId>maven-jar-plugin</artifactId>
161
				<version>2.2</version>
162
				<executions>
163
					<execution>
164
						<goals>
165
							<goal>test-jar</goal>
166
						</goals>
167
					</execution>
168
				</executions>
169
			</plugin>
170
		</plugins>
171
		<pluginManagement>
172
			<plugins>
173
				<!--This plugin's configuration is used to store Eclipse m2e settings 
174
					only. It has no influence on the Maven build itself. -->
175
				<plugin>
176
					<groupId>org.eclipse.m2e</groupId>
177
					<artifactId>lifecycle-mapping</artifactId>
178
					<version>1.0.0</version>
179
					<configuration>
180
						<lifecycleMappingMetadata>
181
							<pluginExecutions>
182
								<pluginExecution>
183
									<pluginExecutionFilter>
184
										<groupId>
185
											org.apache.avro
186
										</groupId>
187
										<artifactId>
188
											avro-maven-plugin
189
										</artifactId>
190
										<versionRange>
191
											[1.7.4,)
192
										</versionRange>
193
										<goals>
194
											<goal>schema</goal>
195
											<goal>idl-protocol</goal>
196
										</goals>
197
									</pluginExecutionFilter>
198
									<action>
199
										<ignore />
200
									</action>
201
								</pluginExecution>
202
								<pluginExecution>
203
									<pluginExecutionFilter>
204
										<groupId>
205
											org.codehaus.mojo
206
										</groupId>
207
										<artifactId>
208
											build-helper-maven-plugin
209
										</artifactId>
210
										<versionRange>
211
											[1.7,)
212
										</versionRange>
213
										<goals>
214
											<goal>add-source</goal>
215
										</goals>
216
									</pluginExecutionFilter>
217
									<action>
218
										<ignore />
219
									</action>
220
								</pluginExecution>
221
							</pluginExecutions>
222
						</lifecycleMappingMetadata>
223
					</configuration>
224
				</plugin>
225
			</plugins>
226
		</pluginManagement>
227
	</build>
228
	<repositories>
229
		<repository>
230
			<id>cloudera</id>
231
			<url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
232
			<releases>
233
				<enabled>true</enabled>
234
			</releases>
235
			<snapshots>
236
				<enabled>false</enabled>
237
			</snapshots>
238
		</repository>
239
	</repositories>
240
</project>
0 241

  
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/OozieTestsIOUtils.java
1
package eu.dnetlib.iis.core;
2

  
3
import java.io.DataInputStream;
4
import java.io.DataOutputStream;
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.FileOutputStream;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.io.OutputStream;
11

  
12
import org.apache.hadoop.conf.Configuration;
13
import org.apache.hadoop.fs.FileSystem;
14
import org.apache.hadoop.fs.Path;
15
import org.apache.oozie.util.IOUtils;
16

  
17
/**
18
 * Provides Oozie-related IO methods
19
 * @author Mateusz Kobos
20
 *
21
 */
22
public class OozieTestsIOUtils {
23
	private FileSystem fs;
24
	private final static String confStorageDirProperty = "hadoop.log.dir";
25
	private final static String confStorageFileName = "shared_configuration.conf";
26
	
27
	public OozieTestsIOUtils(FileSystem fs) {
28
		this.fs = fs;
29
	}
30
	
31
	public void copyResourceToHDFS(String resourcePath, Path destination)
32
			throws IOException {
33
		InputStream in = IOUtils.getResourceAsStream(resourcePath, -1);
34
		OutputStream out = fs.create(destination);
35
		IOUtils.copyStream(in, out);
36
	}
37

  
38
	public void copyLocalToHDFS(File source, Path destination)
39
			throws IOException {
40
		Path srcPath = new Path(source.getAbsolutePath());
41
		fs.copyFromLocalFile(srcPath, destination);
42
	}
43
	
44
//	public void copyHDFSToLocal(Path source, File destination) 
45
//			throws IOException{
46
//		InputStream in = fs.open(source);
47
//		OutputStream out = new FileOutputStream(destination);
48
//		IOUtils.copyStream(in, out);
49
//	}
50
	
51
	/** Saves the configuration in a local working directory created by 
52
	 * Oozie test case for given test method. This method should be called
53
	 * from the inside of an Oozie test case method, otherwise its functioning
54
	 * is undefined. The saved information can be retrieved by calling 
55
	 * {@link loadConfiguration()}.
56
	 * 
57
	 * @param conf configuration that should be retrieved from the inside of
58
	 * the Oozie test case method by calling {@link createJobConf()}
59
	 * @throws IOException
60
	 */
61
	public static void saveConfiguration(Configuration conf) throws IOException{
62
		File f = new File(System.getProperty(confStorageDirProperty), 
63
				confStorageFileName);
64
		DataOutputStream out = new DataOutputStream(new FileOutputStream(f));
65
		conf.write(out);
66
		out.close();
67
	}
68
	
69
	/** A counterpart of the {@link saveConfiguration()} method. It should be
70
	 * called from the inside of a code run on the Hadoop created 
71
	 * by Oozie test case.
72
	 * 
73
	 * @return
74
	 * @throws IOException
75
	 */
76
	public static Configuration loadConfiguration() throws IOException{
77
		File f = new File(System.getProperty(confStorageDirProperty), 
78
				confStorageFileName);
79
		DataInputStream in = new DataInputStream(new FileInputStream(f));
80
		Configuration conf = new Configuration();
81
		conf.readFields(in);
82
		in.close();
83
		return conf;
84
	}
85
	
86
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/CmdLineParserForProcessRunParametersTest.java
1
package eu.dnetlib.iis.core.java;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import java.net.URISyntaxException;
6
import java.util.HashMap;
7
import java.util.Map;
8

  
9
import org.apache.commons.cli.CommandLine;
10
import org.apache.hadoop.fs.Path;
11
import org.junit.Test;
12

  
13
import eu.dnetlib.iis.core.java.CmdLineParserException;
14
import eu.dnetlib.iis.core.java.CmdLineParserForProcessRunParameters;
15
import eu.dnetlib.iis.core.java.PortBindings;
16
import eu.dnetlib.iis.core.java.Ports;
17
import eu.dnetlib.iis.core.java.ProcessParameters;
18
import eu.dnetlib.iis.core.java.porttype.AnyPortType;
19
import eu.dnetlib.iis.core.java.porttype.PortType;
20

  
21
/**
22
 * 
23
 * @author Mateusz Kobos
24
 *
25
 */
26
public class CmdLineParserForProcessRunParametersTest{
27

  
28
	@Test
29
	public void testBasic() throws URISyntaxException {
30
		CmdLineParserForProcessRunParameters parser = 
31
				new CmdLineParserForProcessRunParameters();
32
		String[] args = new String[]{
33
				"-Iperson=/users/joe/person_input",
34
				"-Idocument=/users/joe/doc_input",
35
				"-Omerged=/users/joe/merged_out",
36
				"-Page=33"};
37
		Ports ports = createStandardPorts();
38
		CommandLine cmdLine = CmdLineParser.parse(args);
39
		ProcessParameters actual = parser.run(cmdLine, ports);
40
		ProcessParameters expected = createStandardCmdLineParams();
41
		
42
		assertEquals(expected, actual);
43
	}
44
	
45
	@Test(expected=CmdLineParserException.class)
46
	public void testTooManyPorts() {
47
		CmdLineParserForProcessRunParameters parser = 
48
				new CmdLineParserForProcessRunParameters();
49
		String[] args = new String[]{
50
				"-Iperson=/users/joe/person_input",
51
				"-Idocument=/users/joe/doc_input",
52
				"-Omerged=/users/joe/merged_out",
53
				"-Oother=/users/joe/other_out"};
54
		Ports ports = createStandardPorts();
55
		CommandLine cmdLine = CmdLineParser.parse(args);
56
		parser.run(cmdLine, ports);
57
	}
58
	
59
	@Test(expected=CmdLineParserException.class)
60
	public void testTooFewPorts() {
61
		CmdLineParserForProcessRunParameters parser = 
62
				new CmdLineParserForProcessRunParameters();
63
		String[] args = new String[]{
64
				"-Iperson=/users/joe/person_input",
65
				"-Omerged=/users/joe/merged_out"};
66
		Ports ports = createStandardPorts();
67
		CommandLine cmdLine = CmdLineParser.parse(args);
68
		parser.run(cmdLine, ports);
69
	}
70
	
71
	private static Ports createStandardPorts(){
72
		HashMap<String, PortType> inputPorts = 
73
				new HashMap<String, PortType>();
74
		inputPorts.put("person", new AnyPortType());
75
		inputPorts.put("document", new AnyPortType());
76
		HashMap<String, PortType> outputPorts = 
77
				new HashMap<String, PortType>();
78
		outputPorts.put("merged", new AnyPortType());
79
		return new Ports(inputPorts, outputPorts);	
80
	}
81
	
82
	private static ProcessParameters createStandardCmdLineParams() 
83
			throws URISyntaxException{
84
		HashMap<String, Path> inputBinding = new HashMap<String, Path>();
85
		inputBinding.put("person", 
86
				new Path("/users/joe/person_input"));
87
		inputBinding.put("document", 
88
				new Path("/users/joe/doc_input"));
89
		HashMap<String, Path> outputBinding = new HashMap<String, Path>();
90
		outputBinding.put("merged", 
91
				new Path("/users/joe/merged_out"));
92
		PortBindings expectedBindings = 
93
				new PortBindings(inputBinding, outputBinding);
94
		Map<String, String> params = new HashMap<String, String>();
95
		params.put("age", "33");
96
		ProcessParameters cmdLineParams = new ProcessParameters(
97
				expectedBindings, params);
98
		return cmdLineParams;
99
	}
100
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/io/JsonStreamWriterTest.java
1
package eu.dnetlib.iis.core.java.io;
2

  
3
import java.io.ByteArrayOutputStream;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.StringWriter;
7
import java.util.List;
8

  
9
import org.apache.commons.io.IOUtils;
10
import org.junit.Test;
11
import junit.framework.Assert;
12

  
13
import eu.dnetlib.iis.core.schemas.standardexamples.Document;
14

  
15
/**
16
 * @author Mateusz Kobos
17
 */
18
public class JsonStreamWriterTest {
19
	
20
	@Test
21
	public void basicTest() throws IOException{
22
		ByteArrayOutputStream out = new ByteArrayOutputStream();
23
		JsonStreamWriter<Document> writer = 
24
				new JsonStreamWriter<Document>(Document.SCHEMA$, out);
25
		List<Document> documents = DataStoreExamples.getDocument();
26
		for(Document d: documents){
27
			writer.write(d);
28
		}
29
		writer.close();
30
		String actual = out.toString();
31
		InputStream in = Thread.currentThread().getContextClassLoader()
32
			.getResourceAsStream("eu/dnetlib/iis/core/java/io/document.json");
33
		String expected = toString(in);
34
		Assert.assertEquals(expected, actual);
35
	}
36
	
37
	private static String toString(InputStream in) throws IOException{
38
		StringWriter writer = new StringWriter();
39
		IOUtils.copy(in, writer);
40
		return writer.toString();
41
	}
42
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/io/DataStoreTest.java
1
package eu.dnetlib.iis.core.java.io;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.List;
8
import java.util.NoSuchElementException;
9

  
10
import org.apache.avro.Schema;
11
import org.apache.avro.file.DataFileWriter;
12
import org.apache.avro.generic.GenericContainer;
13
import org.apache.commons.io.FileUtils;
14
import org.junit.After;
15
import org.junit.Assert;
16
import org.junit.Before;
17
import org.junit.Test;
18

  
19
import com.google.common.io.Files;
20

  
21
import eu.dnetlib.iis.core.TestsIOUtils;
22
import eu.dnetlib.iis.core.schemas.standardexamples.Document;
23
import eu.dnetlib.iis.core.schemas.standardexamples.DocumentWithoutTitle;
24
import eu.dnetlib.iis.core.java.io.AvroDataStoreReader;
25
import eu.dnetlib.iis.core.java.io.DataStore;
26
import eu.dnetlib.iis.core.java.io.FileSystemPath;
27

  
28

  
29
/**
30
 * @author Mateusz Kobos
31
 */
32
public class DataStoreTest {
33

  
34
	private File tempDir = null;
35
	
36
	@Before
37
	public void setUp() throws IOException{
38
		tempDir = Files.createTempDir();
39
	}
40
	
41
	@After
42
	public void tearDown() throws IOException{
43
		FileUtils.deleteDirectory(tempDir);
44
	}
45
	
46
	@Test
47
	public void testSingleFile() throws IOException {
48
		List<Document> documents = DataStoreExamples.getDocument();
49
		FileSystemPath path = new FileSystemPath(new File(tempDir, "doc"));
50
		DataStore.create(documents, path);
51
		TestsIOUtils.assertEqualSets(documents, 
52
				new AvroDataStoreReader<Document>(path));	
53
	}
54
	
55
	@Test
56
	public void testReaderSchema() throws IOException {
57
		List<Document> documents = DataStoreExamples.getDocument();
58
		FileSystemPath path = new FileSystemPath(new File(tempDir, "doc"));
59
		DataStore.create(documents, path);
60
		List<DocumentWithoutTitle> documentsWithoutTitle = 
61
				DataStoreExamples.getDocumentWithoutTitle();
62
		TestsIOUtils.assertEqualSets(documentsWithoutTitle, 
63
				new AvroDataStoreReader<DocumentWithoutTitle>(
64
						path, DocumentWithoutTitle.SCHEMA$));	
65
	}
66
	
67
	@Test
68
	public void testClose() throws IOException{
69
		List<Document> documents = DataStoreExamples.getDocument();
70
		FileSystemPath path = new FileSystemPath(new File(tempDir, "doc"));
71
		DataStore.create(documents, path);
72
		AvroDataStoreReader<Document> reader = 
73
				new AvroDataStoreReader<Document>(path);
74
		Assert.assertEquals(documents.get(0), reader.next());
75
		Assert.assertEquals(documents.get(1), reader.next());
76
		reader.close();
77
		try{
78
			reader.next();
79
			Assert.fail("Didn't throw an exception when it supposed to");
80
		} catch(NoSuchElementException ex){
81
		}
82
	}
83
	
84
	@Test
85
	public void testManyFiles() throws IOException{
86
		List<Document> documents = DataStoreExamples.getDocument();
87
		createSingleFile(documents.subList(0, 3), 
88
				new FileSystemPath(new File(tempDir, "doc0")), 
89
				Document.SCHEMA$);
90
		createSingleFile(documents.subList(3, 4), 
91
				new FileSystemPath(new File(tempDir, "doc1")),
92
				Document.SCHEMA$);
93
	
94
		TestsIOUtils.assertEqualSets(documents, 
95
				new AvroDataStoreReader<Document>(
96
						new FileSystemPath(tempDir)));	
97
	}
98
	
99
	@Test
100
	public void testEmptyFiles() throws IOException{
101
		List<Document> documents = DataStoreExamples.getDocument();
102

  
103
		createSingleFile(documents.subList(0, 3), 
104
				new FileSystemPath(new File(tempDir, "doc0")),
105
				Document.SCHEMA$);
106
		
107
		createSingleFile(Arrays.<Document>asList(), 
108
				new FileSystemPath(new File(tempDir, "doc881")),
109
				Document.SCHEMA$);
110
		
111
		createSingleFile(documents.subList(3, 4), 
112
				new FileSystemPath(new File(tempDir, "doc22")),
113
				Document.SCHEMA$);
114

  
115
		createSingleFile(Arrays.<Document>asList(), 
116
				new FileSystemPath(new File(tempDir, "doc4")),
117
				Document.SCHEMA$);
118
		
119
		TestsIOUtils.assertEqualSets(documents, 
120
				new AvroDataStoreReader<Document>(
121
						new FileSystemPath(tempDir)));	
122
	}
123
	
124
	private static <T extends GenericContainer> void createSingleFile(
125
			List<T> elements, FileSystemPath path, Schema schema) 
126
					throws IOException{
127
		DataFileWriter<T> writer = DataStore.createSingleFile(path, schema);
128
		for(T i: elements){
129
			writer.append(i);
130
		}
131
		writer.close();
132
	}
133
}
134

  
135
class DataStoreExamples{
136
	static String bookTitleExtra = "An extraordinary book";
137
	static String bookTitleBasics = "Basics of the basics";
138
	static String bookTitleMoreInteresting = "Even more of interesting stuff";
139
	static String bookTitleEscapeCodes = "2.2. Stellar Rotation Hertszprung\u2013Russell diagram precludes detecting\n6.2. Conclusions\n";
140
		
141
	/**
142
	 * Sample data on some documents
143
	 */
144
	public static List<Document> getDocument(){
145
		ArrayList<Document> list = new ArrayList<Document>();
146
		list.add(new Document(20, bookTitleExtra,
147
				new ArrayList<Integer>(Arrays.asList(1, 20))));
148
		list.add(new Document(1, bookTitleBasics,
149
				new ArrayList<Integer>(Arrays.asList(10, 6, 1))));
150
		list.add(new Document(2, null, 
151
				new ArrayList<Integer>()));
152
		list.add(new Document(6, bookTitleMoreInteresting,
153
				new ArrayList<Integer>(Arrays.asList(1, 6))));
154
		return list;
155
	}
156
	
157
	/**
158
	 * The same as the {@link getDocument} but does not include document title
159
	 */
160
	public static List<DocumentWithoutTitle> getDocumentWithoutTitle(){
161
		ArrayList<DocumentWithoutTitle> list = new ArrayList<DocumentWithoutTitle>();
162
		list.add(new DocumentWithoutTitle(20, 
163
				new ArrayList<Integer>(Arrays.asList(1, 20))));
164
		list.add(new DocumentWithoutTitle(1, 
165
				new ArrayList<Integer>(Arrays.asList(10, 6, 1))));
166
		list.add(new DocumentWithoutTitle(2,
167
				new ArrayList<Integer>()));
168
		list.add(new DocumentWithoutTitle(6, 
169
				new ArrayList<Integer>(Arrays.asList(1, 6))));
170
		return list;
171
	}
172
	
173
	public static List<Document> getDocumentWithUnicodeEscapeCodes(){
174
		ArrayList<Document> list = new ArrayList<Document>();
175
		list.add(new Document(20, bookTitleEscapeCodes,
176
				new ArrayList<Integer>(Arrays.asList(1, 20))));
177
		return list;
178
	}
179
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/io/JsonStreamReaderTest.java
1
package eu.dnetlib.iis.core.java.io;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
import org.junit.Test;
9

  
10
import eu.dnetlib.iis.core.TestsIOUtils;
11
import eu.dnetlib.iis.core.schemas.standardexamples.Document;
12

  
13
/**
14
 * @author Mateusz Kobos
15
 */
16
public class JsonStreamReaderTest {
17
	
18
	@Test
19
	public void basicTest() throws IOException{
20
		InputStream in = Thread.currentThread().getContextClassLoader()
21
			.getResourceAsStream("eu/dnetlib/iis/core/java/io/document.json");
22
		CloseableIterator<Document> reader = new JsonStreamReader<Document>(
23
				Document.SCHEMA$, in, Document.class);
24
		List<Document> expected = DataStoreExamples.getDocument();
25
		List<Document> actual = new ArrayList<Document>();
26
		while(reader.hasNext()){
27
			Object record = reader.next();
28
			Document read = (Document) record;
29
			actual.add(read);
30
		}
31
		TestsIOUtils.assertEqualSets(expected, actual);	
32
	}
33
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/io/JsonUtilsTest.java
1
package eu.dnetlib.iis.core.java.io;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.util.List;
7

  
8
import junit.framework.Assert;
9

  
10
import org.apache.avro.Schema;
11
import org.apache.commons.io.FileUtils;
12
import org.apache.commons.io.IOUtils;
13
import org.junit.After;
14
import org.junit.Before;
15
import org.junit.Test;
16

  
17
import com.google.common.io.Files;
18

  
19
import eu.dnetlib.iis.core.TestsIOUtils;
20
import eu.dnetlib.iis.core.schemas.standardexamples.Document;
21

  
22
/**
23
 * 
24
 * @author Mateusz Kobos
25
 *
26
 */
27
public class JsonUtilsTest {
28
	private File tempDir = null;
29
	
30
	@Before
31
	public void setUp() throws IOException{
32
		tempDir = Files.createTempDir();
33
	}
34
	
35
	@After
36
	public void tearDown() throws IOException{
37
		FileUtils.deleteDirectory(tempDir);
38
	}
39
	
40
	@Test
41
	public void testConvertToDataStoreSimple() throws IOException{
42
		checkConvertToDataStore(DataStoreExamples.getDocument(), 
43
				"eu/dnetlib/iis/core/java/io/document.json", Document.SCHEMA$);
44
	}
45
	
46
	@Test
47
	public void testConvertToDataStoreWithEscapeCodes() throws IOException{
48
		checkConvertToDataStore(DataStoreExamples.getDocumentWithUnicodeEscapeCodes(), 
49
				"eu/dnetlib/iis/core/java/io/document_with_unicode_escape_codes.json", 
50
				Document.SCHEMA$);
51
	}
52
	
53
	private <T> void checkConvertToDataStore(List<T> expectedRecords,
54
			String actualResourcePath, Schema actualSchema) throws IOException{
55
		InputStream in = Thread.currentThread().getContextClassLoader()
56
				.getResourceAsStream(actualResourcePath);
57
		FileSystemPath outPath = new FileSystemPath(new File(tempDir, "record"));
58
		JsonUtils.convertToDataStore(actualSchema, in, outPath);
59
		TestsIOUtils.assertEqualSets(expectedRecords, 
60
				new AvroDataStoreReader<T>(outPath));
61
	}
62
	
63
	@Test
64
	public void testConvertToListWithUnicodeEscapeCodes() throws IOException{
65
		List<Document> actual = JsonUtils.convertToList(
66
				"eu/dnetlib/iis/core/java/io/document_with_unicode_escape_codes.json",
67
				Document.SCHEMA$, Document.class);
68
		List<Document> expected = DataStoreExamples.getDocumentWithUnicodeEscapeCodes();
69
		TestsIOUtils.assertEqualSets(expected, actual);			
70
	}
71
	
72
	@Test
73
	public void testPrettyPrint() throws IOException{
74
		String uglyJson = getStringFromResourceFile(
75
				"eu/dnetlib/iis/core/java/io/json_pretty_print/ugly_json.json");
76
		String actual = JsonUtils.toPrettyJSON(uglyJson);
77
		String expected = getStringFromResourceFile(
78
				"eu/dnetlib/iis/core/java/io/json_pretty_print/expected_pretty_json.json");
79
		Assert.assertEquals(expected, actual);
80
	}
81
	
82
	private String getStringFromResourceFile(String resourcePath) throws IOException{
83
		InputStream in = Thread.currentThread().getContextClassLoader()
84
				.getResourceAsStream(resourcePath);
85
		return IOUtils.toString(in, "UTF-8");
86
	}
87
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/CmdLineParserForProcessConstructionTest.java
1
package eu.dnetlib.iis.core.java;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import java.util.Map;
6

  
7
import org.apache.commons.cli.CommandLine;
8
import org.apache.hadoop.conf.Configuration;
9
import org.junit.Test;
10

  
11
import eu.dnetlib.iis.core.java.porttype.PortType;
12

  
13
/**
14
 * 
15
 * @author Mateusz Kobos
16
 *
17
 */
18
class DummyProcess implements Process {
19

  
20
	public DummyProcess(){	
21
	}
22
	
23
	@Override
24
	public Map<String, PortType> getInputPorts() {
25
		return null;
26
	}
27
	
28
	@Override
29
	public Map<String, PortType> getOutputPorts(){
30
		return null;
31
	}
32

  
33
	@Override
34
	public void run(PortBindings portBindings, Configuration configuration, 
35
			Map<String, String> parameters){
36
	}
37
}
38

  
39
class DummyProcessWithParametersConstructor implements Process{
40
	public String[] params;
41
	
42
	
43
	public DummyProcessWithParametersConstructor(String[] params){
44
		this.params = params;
45
	}
46

  
47
	@Override
48
	public Map<String, PortType> getInputPorts() {
49
		return null;
50
	}
51

  
52
	@Override
53
	public Map<String, PortType> getOutputPorts() {
54
		return null;
55
	}
56

  
57
	@Override
58
	public void run(PortBindings portBindings, Configuration configuration,
59
			Map<String, String> parameters) throws Exception {
60
	}
61
	
62
}
63

  
64
public class CmdLineParserForProcessConstructionTest{
65

  
66
	@Test
67
	public void testTrivial() {
68
		String[] args = new String[]{
69
				"eu.dnetlib.iis.core.java.DummyProcess"};
70
		CmdLineParserForProcessConstruction cmdLineParser = 
71
				new CmdLineParserForProcessConstruction();
72
		CommandLine cmdLine = CmdLineParser.parse(args);
73
		Process actual = cmdLineParser.run(cmdLine);
74
		assertEquals(DummyProcess.class, actual.getClass());
75
	}
76
	
77
	@Test
78
	public void testWithSomeParameters() {
79
		String[] args = new String[]{
80
				"eu.dnetlib.iis.core.java.DummyProcess",
81
				"-Iperson=hdfs://localhost:8020/users/joe/person_input",
82
				"-Idocument=hdfs://localhost:8020/users/joe/doc_input",
83
				"-Omerged=hdfs://localhost:8020/users/joe/merged_out",
84
				"-SclassName=java.util.String"};
85
		CmdLineParserForProcessConstruction cmdLineParser = 
86
				new CmdLineParserForProcessConstruction();
87
		CommandLine cmdLine = CmdLineParser.parse(args);
88
		Process actual = cmdLineParser.run(cmdLine);
89
		assertEquals(DummyProcess.class, actual.getClass());
90
	}
91
	
92
	@Test
93
	public void testWithSomeParametersWithParametersConstructor() {
94
		String[] constructorParams = new String[]{
95
				"some string", "some other string"};
96
		String[] args = new String[]{
97
				"eu.dnetlib.iis.core.java.DummyProcessWithParametersConstructor",
98
				"-C" + constructorParams[0],
99
				"-C" + constructorParams[1],
100
				"-Iperson=hdfs://localhost:8020/users/joe/person_input",
101
				"-Idocument=hdfs://localhost:8020/users/joe/doc_input",
102
				"-Omerged=hdfs://localhost:8020/users/joe/merged_out",
103
				"-SclassName=java.util.String"};
104
		CmdLineParserForProcessConstruction cmdLineParser = 
105
				new CmdLineParserForProcessConstruction();
106
		CommandLine cmdLine = CmdLineParser.parse(args);
107
		DummyProcessWithParametersConstructor actual = 
108
				(DummyProcessWithParametersConstructor) cmdLineParser.run(cmdLine);
109
		assertEquals(DummyProcessWithParametersConstructor.class, 
110
				actual.getClass());
111
		for(int i = 0; i < constructorParams.length; i++){
112
			assertEquals(constructorParams[i], actual.params[i]);
113
		}
114
		
115
	}
116
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/ProcessWrapperForTests.java
1
package eu.dnetlib.iis.core.java;
2

  
3
import org.apache.hadoop.conf.Configuration;
4

  
5
import eu.dnetlib.iis.core.OozieTestsIOUtils;
6
import eu.dnetlib.iis.core.java.ProcessWrapper;
7

  
8
/**
9
 * A version of the {@link ProcessWrapper} which uses the Configuration
10
 * object created by the Oozie unit test framework. This is used in the
11
 * XML workflow definition in the tests instead of {@link ProcessWrapper}. 
12
 * It makes referencing the underlying file system by the java Process run
13
 * during the tests possible.
14
 * @author Mateusz Kobos
15
 * 
16
 */
17
public class ProcessWrapperForTests extends ProcessWrapper {
18
	public Configuration getConfiguration() throws Exception {
19
		return OozieTestsIOUtils.loadConfiguration();
20
	}
21
	
22
	public static void main(String[] args) throws Exception {
23
		ProcessWrapper wrapper = new ProcessWrapperForTests();
24
		wrapper.run(args);
25
	}
26
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/jsonworkflownodes/ProducerAndConsumerTest.java
1
package eu.dnetlib.iis.core.java.jsonworkflownodes;
2

  
3
import java.util.Map;
4

  
5
import junit.framework.Assert;
6

  
7
import org.junit.Test;
8

  
9
import eu.dnetlib.iis.core.common.AvroUtils;
10
import eu.dnetlib.iis.core.java.porttype.AvroPortType;
11
import eu.dnetlib.iis.core.java.porttype.PortType;
12

  
13
public class ProducerAndConsumerTest{
14
	@Test
15
	public void testPortCreationInProducer(){
16
		checkPortsCreator(new PortsCreator() {
17
			@Override 
18
			public Map<String, PortType> getPorts(String[] specificationStrings){
19
				Producer producer = 
20
						new Producer(specificationStrings);
21
				Assert.assertEquals(0, producer.getInputPorts().size());
22
				return producer.getOutputPorts();
23
			}
24
		});
25
	}
26
	
27
	@Test
28
	public void testPortCreationInTestingConsumer(){
29
		checkPortsCreator(new PortsCreator() {
30
			@Override 
31
			public Map<String, PortType> getPorts(String[] specificationStrings){
32
				TestingConsumer consumer = 
33
						new TestingConsumer(specificationStrings);
34
				Assert.assertEquals(0, consumer.getOutputPorts().size());
35
				return consumer.getInputPorts();
36
			}
37
		});
38
	}
39
	
40
	private void checkPortsCreator(PortsCreator creator) {
41
		PortSpec[] specs = new PortSpec[] {
42
				new PortSpec(
43
						"document",
44
						"eu.dnetlib.iis.core.schemas.standardexamples.Document",
45
						"fake/path/document.json"),
46
				new PortSpec("person",
47
						"eu.dnetlib.iis.core.schemas.standardexamples.Person",
48
						"fake/path/person.json") };
49
		String[] specsStr = new String[specs.length];
50
		for (int i = 0; i < specs.length; i++) {
51
			specsStr[i] = String.format("{%s, %s, %s}", specs[i].name,
52
					specs[i].schemaPath, specs[i].jsonPath);
53
		}
54
		Map<String, PortType> outs = creator.getPorts(specsStr);
55
		Assert.assertEquals(specs.length, outs.size());
56
		for (int i = 0; i < specs.length; i++) {
57
			AvroPortType actual = (AvroPortType) outs.get(specs[i].name);
58
			AvroPortType expected = new AvroPortType(
59
					AvroUtils.toSchema(specs[i].schemaPath));
60
			Assert.assertEquals(expected, actual);
61
		}
62
	}
63
}
64

  
65
interface PortsCreator{
66
	Map<String, PortType> getPorts(String[] specificationStrings);
67
}
68

  
69
class PortSpec{
70
	public String name;
71
	public String schemaPath;
72
	public String jsonPath;
73
	
74
	public PortSpec(String name, String schemaPath, String jsonPath){
75
		this.name = name;
76
		this.schemaPath = schemaPath;
77
		this.jsonPath = jsonPath;
78
	}
79
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/jsonworkflownodes/package-info.java
1
/** The package contains producer and consumer workflow nodes that are 
2
 * configured using JSON format to respectively produce and consume 
3
 * data stores. 
4
 */
5
package eu.dnetlib.iis.core.java.jsonworkflownodes;
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/java/jsonworkflownodes/TestingConsumer.java
1
package eu.dnetlib.iis.core.java.jsonworkflownodes;
2

  
3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import org.apache.avro.specific.SpecificRecord;
9
import org.apache.hadoop.conf.Configuration;
10
import org.apache.hadoop.fs.FileSystem;
11
import org.apache.hadoop.fs.Path;
12

  
13
import eu.dnetlib.iis.core.TestsIOUtils;
14
import eu.dnetlib.iis.core.java.PortBindings;
15
import eu.dnetlib.iis.core.java.Process;
16
import eu.dnetlib.iis.core.java.io.DataStore;
17
import eu.dnetlib.iis.core.java.io.FileSystemPath;
18
import eu.dnetlib.iis.core.java.io.JsonUtils;
19
import eu.dnetlib.iis.core.java.jsonworkflownodes.PortSpecifications.SpecificationValues;
20
import eu.dnetlib.iis.core.java.porttype.PortType;
21

  
22
/**
23
 * Reads the data stores from specified input ports and compares them with
24
 * expected JSON-encoded data stores. If There is a mismatch,
25
 * an exception is thrown.
26
 *
27
 * @author Mateusz Kobos
28
 */
29
public class TestingConsumer implements Process {
30
	private final PortSpecifications inputSpecs;
31
	
32
	/**
33
	 * @param inputSpecifications specifications of input. Each element of
34
	 * the array corresponds to a single specification. Single specification
35
	 * conforms to the following template:
36
	 * "{input port name, schema reference, path to JSON file in resources 
37
	 * corresponding to the expected input data store}",
38
	 * e.g. "{person, eu.dnetlib.iis.core.examples.schemas.documentandauthor.Person, 
39
	 * eu/dnetlib/iis/core/examples/person.json}"
40
	 */
41
	public TestingConsumer(String[] inputSpecifications){
42
		inputSpecs = new PortSpecifications(inputSpecifications);
43
	}
44
	
45
	@Override
46
	public Map<String, PortType> getInputPorts() {
47
		return inputSpecs.getPortTypes();
48
	}
49

  
50
	@Override
51
	public Map<String, PortType> getOutputPorts() {
52
		return new HashMap<String, PortType>();
53
	}
54

  
55
	@Override
56
	public void run(PortBindings portBindings, Configuration configuration,
57
			Map<String, String> parameters) throws Exception {
58
		Map<String, Path> input = portBindings.getInput();
59
		FileSystem fs = FileSystem.get(configuration);
60
		for(Map.Entry<String, Path> e: input.entrySet()){
61
			SpecificationValues specs = inputSpecs.get(e.getKey());
62
			check(new FileSystemPath(fs, e.getValue()), specs);
63
		}
64
	}
65
	
66
	private static void check(FileSystemPath actualPath, SpecificationValues specs) throws IOException{
67
		List<SpecificRecord> expected = JsonUtils.convertToList(
68
				specs.jsonFilePath, specs.schema, SpecificRecord.class);
69
		List<SpecificRecord> actual = DataStore.read(actualPath, specs.schema);
70
		TestsIOUtils.assertEqualSets(expected, actual, true);
71
	}
72
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/WorkflowConfiguration.java
1
package eu.dnetlib.iis.core;
2

  
3
import java.util.Properties;
4

  
5
import org.apache.oozie.client.WorkflowJob;
6

  
7
/**
8
 * Configuration of the testing workflow
9
 * @author Mateusz Kobos
10
 */
11
public class WorkflowConfiguration {
12
	
13
	/** I had to change the duration of the wait from the original 
14
	 * 15 seconds because the original time wasn't enough for my 
15
	 * computer to execute the Oozie workflow. To be more precise, 
16
	 * the test ended with the following failure message: 
17
	 * junit.framework.AssertionFailedError: expected:<SUCCEEDED> but was:<RUNNING>
18
	 */
19
	public static final int defaultTimeoutInSeconds = 360;
20
	public static final WorkflowJob.Status defaultExpectedFinishStatus = 
21
			WorkflowJob.Status.SUCCEEDED;
22
	public static final Properties defaultJobProperties = null;
23
	
24
	private Properties jobProps = defaultJobProperties; 
25
	private int timeoutInSeconds = defaultTimeoutInSeconds;
26
	private WorkflowJob.Status expectedFinishStatus = defaultExpectedFinishStatus;
27
	
28
	public WorkflowConfiguration(){
29
	}
30

  
31
	/**
32
	 * See {@link #setJobProps} for description
33
	 * @return
34
	 */
35
	public Properties getJobProps() {
36
		return jobProps;
37
	}
38
	/**
39
	 * @param jobProps job properties
40
	 */
41
	public WorkflowConfiguration setJobProps(Properties jobProps) {
42
		this.jobProps = jobProps;
43
		return this;
44
	}
45
	
46
	/**
47
	 * See {@link #setTimeoutInSeconds} for description
48
	 */
49
	public int getTimeoutInSeconds() {
50
		return timeoutInSeconds;
51
	}
52
	/**
53
	 * @param timeoutInSeconds timeout in seconds. Workflow will be killed
54
     * if timeout is exceeded
55
	 */
56
	public WorkflowConfiguration setTimeoutInSeconds(int timeoutInSeconds) {
57
		this.timeoutInSeconds = timeoutInSeconds;
58
		return this;
59
	}
60
	
61
	/**
62
	 * See {@link #setExpectedFinishStatus} for description
63
	 * @return
64
	 */
65
	public WorkflowJob.Status getExpectedFinishStatus() {
66
		return expectedFinishStatus;
67
	}
68
	/**
69
	 * @param expectedFinishStatus expected status of the workflow after its
70
	 * finish
71
	 */
72
	public WorkflowConfiguration setExpectedFinishStatus(WorkflowJob.Status expectedFinishStatus) {
73
		this.expectedFinishStatus = expectedFinishStatus;
74
		return this;
75
	}
76
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/StringReplacer.java
1
package eu.dnetlib.iis.core;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileReader;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.PrintWriter;
9
import java.util.ArrayList;
10
import java.util.List;
11

  
12
/**
13
 * Replace strings conforming to given regexes "on the flight", i.e. while copying
14
 * file from one place to another.
15
 *
16
 * This is used in order to change the Oozie's "workflow.xml" so that it 
17
 * conforms to the requirements of the MiniOozie testing engine.
18
 * 
19
 * @author Mateusz Kobos
20
 *
21
 */
22
public class StringReplacer {
23
	private static final List<StringReplacement> replacements = getReplacements();
24
	
25
	private static List<StringReplacement> getReplacements(){
26
		List<StringReplacement> list = new ArrayList<StringReplacement>();
27

  
28
		/** We have to use a special wrapper for Java workflow nodes in order
29
		 * to make them use the special mock HDFS used during the tests.
30
		 */
31
		list.add(new StringReplacement(
32
				"ProcessWrapper", 
33
				"ProcessWrapperForTests"));
34

  
35
		/** The paths to Avro schemas stored in HDFS are understood differently 
36
		 * when running on real cluster and during the tests. When running
37
		 * during the tests, a file system prefix "hdfs://" is absent, which
38
		 * confuses the "avro-json" library that allows for reading and writing
39
		 * Avro files in Hadoop Streaming workflow node. See the code of
40
		 * {@code com.cloudera.science.avro.common.SchemaLoader.loadFromUrl()}
41
		 * method for details where this confusion comes from. 
42
		 * 
43
		 * Here, we're adding a prefix which is the address of the name
44
		 * node which is something that "avro-json" library expects.
45
		 */
46
		list.add(new StringReplacement(
47
				"<value>(\\s*\\$\\{wf:appPath\\(\\)\\}.*\\.avsc\\s*)</value>",
48
				"<value>\\${nameNode}$1</value>"));
49

  
50
		return list;
51
	}
52
	
53
	public void replace(File in, File out) throws IOException {
54
		BufferedReader reader = null;
55
		PrintWriter writer = null;
56
		try {
57
			reader = new BufferedReader(new FileReader(in));
58
			writer = new PrintWriter(new FileWriter(out));
59
			String line = null;
60
			while ((line = reader.readLine()) != null){
61
				String newLine = line;
62
				for(StringReplacement replacement: replacements){
63
					newLine = replacement.replaceAll(newLine);
64
				}
65
				writer.println(newLine);
66
			}
67
		} finally {
68
			if(reader != null){
69
				reader.close();
70
			}
71
			if (writer != null){
72
				writer.close();
73
			}
74
		}
75
	}
76
}
77

  
78
class StringReplacement{
79
	private String regex;
80
	private String replacement;
81
	
82
	public StringReplacement(String regex, String replacement) {
83
		this.regex = regex;
84
		this.replacement = replacement;
85
	}
86
	
87
	public String replaceAll(String str){
88
		return str.replaceAll(regex, replacement);
89
	}
90
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/javamapreduce/hack/SchemaSetterTest.java
1
package eu.dnetlib.iis.core.javamapreduce.hack;
2

  
3
import junit.framework.Assert;
4

  
5
import org.apache.avro.Schema;
6
import org.apache.avro.mapred.Pair;
7
import org.apache.hadoop.conf.Configuration;
8
import org.junit.Test;
9

  
10
import eu.dnetlib.iis.core.schemas.standardexamples.Document;
11
import eu.dnetlib.iis.core.schemas.standardexamples.Person;
12
import eu.dnetlib.iis.core.schemas.standardexamples.personwithdocuments.PersonWithDocuments;
13
import eu.dnetlib.iis.core.javamapreduce.hack.oldapi.SchemaSetter;
14

  
15
public class SchemaSetterTest {
16

  
17
	@Test
18
	public void testBasic() {
19
		Configuration conf = new Configuration();
20
		conf.set(SchemaSetter.inputClassName, 
21
			"eu.dnetlib.iis.core.schemas.standardexamples.Document");
22
		conf.set(SchemaSetter.mapOutputKeyClassName,
23
			SchemaSetter.primitiveTypePrefix+"DOUBLE");
24
		conf.set(SchemaSetter.mapOutputValueClassName,
25
			"eu.dnetlib.iis.core.schemas.standardexamples.Person");
26
		conf.set(SchemaSetter.outputClassName,
27
			"eu.dnetlib.iis.core.schemas.standardexamples.personwithdocuments.PersonWithDocuments");
28
		SchemaSetter.set(conf);
29
		Assert.assertEquals(Document.SCHEMA$.toString(), 
30
				conf.get(SchemaSetter.avroInput));
31
		Assert.assertEquals(Pair.getPairSchema(
32
					Schema.create(Schema.Type.DOUBLE),
33
					Person.SCHEMA$).toString(), 
34
				conf.get(SchemaSetter.avroMapOutput));
35
		Assert.assertEquals(PersonWithDocuments.SCHEMA$.toString(),
36
				conf.get(SchemaSetter.avroOutput));
37
				
38
	}
39

  
40
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/common/AvroToolsTests.java
1
package eu.dnetlib.iis.core.common;
2

  
3
import static org.junit.Assert.*;
4

  
5
import org.junit.Test;
6

  
7
public class AvroToolsTests {
8

  
9
	@Test
10
	public void testToSchemaPrimitiveType() {
11
		checkSchema("\"string\"", "org.apache.avro.Schema.Type.STRING");
12
	}
13
	
14
	@Test
15
	public void testToSchemaClassName(){
16
		checkSchema("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"eu.dnetlib.iis.core.schemas.standardexamples\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"}]}", 
17
				"eu.dnetlib.iis.core.schemas.standardexamples.Person");
18
	}
19
	
20
	private static void checkSchema(String expected, String className){
21
		String actual = AvroUtils.toSchema(className).toString();
22
		assertEquals(expected, actual);
23
	}
24

  
25
}
modules/icm-iis-core/trunk/src/test/java/eu/dnetlib/iis/core/AbstractWorkflowTestCase.java
1
package eu.dnetlib.iis.core;
2

  
3
import java.io.IOException;
4
import java.util.Properties;
5

  
6
import org.apache.commons.logging.LogFactory;
7
import org.apache.hadoop.fs.Path;
8
import org.apache.hadoop.mapred.JobConf;
9
import org.apache.oozie.client.*;
10
import org.apache.oozie.local.LocalOozie;
11
import org.apache.oozie.service.XLogService;
12
import org.apache.oozie.test.MiniOozieTestCase;
13
import org.apache.oozie.util.XLog;
14
import org.junit.After;
15
import org.junit.Before;
16

  
17

  
18
/**
19
 * A basis to be used as a base class of all test case classes that run 
20
 * Oozie workflows.
21
 * <p/>
22
 * ATTENTION: In order for your test case class that has this class as a parent 
23
 * to run properly, the Maven project which contains this class has to have
24
 * a directory called "core" in its root directory with appropriate contents. 
25
 * See the "core" directory in the "icm-iis-core-examples" to see what's 
26
 * the required content of this directory. 
27
 * You can copy this "core" directory to your project.
28
 * <p/>
29
 * <p/>
30
 * If something goes wrong with your test and you want to see the Hadoop logs 
31
 * to check what's the matter, you can look into directory 
32
 * <p/>
33
 * target/test-data/oozietests/NAME_OF_YOUR_TEST_CLASS/NAME_OF_YOUR_TEST_METHOD/userlogs
34
 * <p/>
35
 * and its subdirectories. 
36
 * <p/>
37
 * Unfortunately, I don't know where the files stored in virtual HDFS really 
38
 * are (such an information would also be helpful during debugging).
39
 *  
40
 * @author Mateusz Kobos
41
 *
42
 */
43
public abstract class AbstractWorkflowTestCase extends MiniOozieTestCase {
44

  
45
	private static final char WORKFLOW_LOCATION_SEPARATOR = '/';
46
	
47
	private static final String JOB_PROPERTIES_FILE_NAME = "job.properties";
48
	
49
	@Override
50
	@Before
51
	protected void setUp() throws Exception {
52
		System.setProperty(XLogService.LOG4J_FILE, "oozie-log4j.properties");
53
		log = new XLog(LogFactory.getLog(getClass()));
54
		super.setUp();
55
	}
56

  
57
	@Override
58
	@After
59
	protected void tearDown() throws Exception {
60
		super.tearDown();
61
	}
62
   
63
	/**
64
	 * See {@link #runWorkflow(String resourcesOozieAppLocalPath, WorkflowConfiguration config)}
65
	 * method for description of parameters
66
	 */
67
	public RemoteOozieAppManager runWorkflow(String resourcesOozieAppLocalPath) 
68
			throws IOException, OozieClientException{
69
		return runWorkflow(resourcesOozieAppLocalPath, new WorkflowConfiguration());
70
	}
71
	
72
	/**
73
	 * Run the workflow
74
	 * @param resourcesOozieAppLocalPath path to the directory containing the Oozie
75
     * application. This directory contains the main {@code workflow.xml} file
76
     * @param config optional configuration of the workflow
77
	 */
78
	public RemoteOozieAppManager runWorkflow(
79
			String resourcesOozieAppLocalPath, WorkflowConfiguration config)
80
					throws IOException, OozieClientException{
81
		return runWorkflow(resourcesOozieAppLocalPath, config, false);
82
	}
83
	
84
	/**
85
	 * Run the workflow
86
	 * @param resourcesOozieAppLocalPath path to the directory containing the Oozie
87
     * application. This directory contains the main {@code workflow.xml} file
88
     * @param config optional configuration of the workflow
89
     * @param skipPredefinedJobProperties skips reading predefined job.properties if any set
90
	 */
91
	public RemoteOozieAppManager runWorkflow(
92
			String resourcesOozieAppLocalPath, WorkflowConfiguration config,
93
			boolean skipPredefinedJobProperties)
94
					throws IOException, OozieClientException{
95
//		File oozieAppLocalPath = 
96
//		new File(Thread.currentThread().getContextClassLoader()
97
//				.getResource(resourcesOozieAppLocalPath).getPath());
98
		RemoteOozieAppManager appManager = RemoteOozieAppManager.fromPrimedClassDir(
99
			getFileSystem(), getFsTestCaseDir(), resourcesOozieAppLocalPath);
100
		Properties props = createWorkflowConfiguration(
101
				createJobConf(), getTestUser(),	appManager.getOozieAppPath(), 
102
				appManager.getWorkingDir(), 
103
				skipPredefinedJobProperties?null:
104
						loadPredefinedJobProperties(resourcesOozieAppLocalPath),
105
				config.getJobProps());
106
		runWorkflowBasedOnConfiguration(props, config.getTimeoutInSeconds(),
107
				config.getExpectedFinishStatus());
108
		return appManager;
109
		
110
	}
111
	
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff