INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.integration.samples.fileprocessing;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class FileProcessingTest {
|
||||
private int fileCount = 5;
|
||||
private Logger logger = Logger.getLogger(FileProcessingTest.class);
|
||||
|
||||
@Before
|
||||
public void createDirectory(){
|
||||
File directory = new File("input");
|
||||
if (directory.exists()){
|
||||
directory.delete();
|
||||
}
|
||||
directory.mkdir();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequentialFileProcessing() throws Exception {
|
||||
logger.info("\n\n#### Starting Sequential processing test ####");
|
||||
logger.info("Populating directory with files");
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
File file = new File("input/file_" + i + ".txt");
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
out.write("hello " + i);
|
||||
out.close();
|
||||
}
|
||||
logger.info("Populated directory with files");
|
||||
Thread.sleep(2000);
|
||||
logger.info("Starting Spring Integration Sequential File processing");
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("META-INF/spring/integration/sequentialFileProcessing-config.xml");
|
||||
PollableChannel filesOutChannel = ac.getBean("filesOutChannel", PollableChannel.class);
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
logger.info("Finished processing " + filesOutChannel.receive(10000).getPayload());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testConcurrentFileProcessing() throws Exception {
|
||||
logger.info("\n\n#### Starting Concurrent processing test #### ");
|
||||
logger.info("Populating directory with files");
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
File file = new File("input/file_" + i + ".txt");
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
out.write("hello " + i);
|
||||
out.close();
|
||||
}
|
||||
logger.info("Populated directory with files");
|
||||
Thread.sleep(2000);
|
||||
logger.info("Starting Spring Integration Sequential File processing");
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/concurrentFileProcessing-config.xml");
|
||||
PollableChannel filesOutChannel = ac.getBean("filesOutChannel", PollableChannel.class);
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
logger.info("Finished processing " + filesOutChannel.receive(10000).getPayload());
|
||||
}
|
||||
}
|
||||
}
|
||||
32
intermediate/file-processing/src/test/resources/log4j.xml
Normal file
32
intermediate/file-processing/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.samples.fileprocessing">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.file">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user