Skip to content

Commit

Permalink
File Cleanup - Event to JMX
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Jun 4, 2016
1 parent e16f084 commit 8e36227
Show file tree
Hide file tree
Showing 55 changed files with 202 additions and 152 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
event.types=org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$AnotherSampleEvent, org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$SampleEvent
event.types=org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$AnotherSampleEvent, org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$SampleEvent
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">

<feed:inbound-channel-adapter id="autoChannel"
auto-startup="false"
auto-startup="false"
url="file:dummy.rss">
<int:poller fixed-rate="10000" max-messages-per-poll="100" />
</feed:inbound-channel-adapter>

<int:bridge input-channel="autoChannel" output-channel="nullChannel" />

</beans>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">
<int-feed:inbound-channel-adapter id="feedAdapter"
channel="feedChannel"

<int-feed:inbound-channel-adapter id="feedAdapter"
channel="feedChannel"
url="http://feeds.bbci.co.uk/news/rss.xml"
auto-startup="false">
<int:poller fixed-rate="10000" max-messages-per-poll="100" />
</int-feed:inbound-channel-adapter>

<int:channel id="feedChannel" />

</beans>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.integration.feed.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeast;
Expand All @@ -34,7 +35,7 @@
import org.junit.Test;
import org.mockito.Mockito;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void validateSuccessfulFileConfigurationWithCustomMetadataStore() {
assertEquals(metadataStore, context.getBean("customMetadataStore"));
Object fetcher = TestUtils.getPropertyValue(source, "feedFetcher");
assertEquals("FileUrlFeedFetcher", fetcher.getClass().getSimpleName());
context.destroy();
context.close();
}


Expand All @@ -92,10 +93,10 @@ public void validateSuccessfulHttpConfigurationWithCustomMetadataStore() {
"FeedInboundChannelAdapterParserTests-http-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
MetadataStore metadataStore = (MetadataStore) TestUtils.getPropertyValue(source, "metadataStore");
assertNotNull(TestUtils.getPropertyValue(source, "metadataStore"));
Object fetcher = TestUtils.getPropertyValue(source, "feedFetcher");
assertTrue(fetcher instanceof com.rometools.fetcher.impl.HttpURLFeedFetcher);
context.destroy();
context.close();
}

@Test
Expand All @@ -111,7 +112,7 @@ public void validateSuccessfulNewsRetrievalWithFileUrlAndMessageHistory() throws
"FeedInboundChannelAdapterParserTests-file-usage-context.xml", this.getClass());
latch.await(10, TimeUnit.SECONDS);
verify(latch, times(3)).countDown();
context.destroy();
context.close();

// since we are not deleting the persister file
// in this iteration no new feeds will be received and the latch will timeout
Expand All @@ -120,24 +121,26 @@ public void validateSuccessfulNewsRetrievalWithFileUrlAndMessageHistory() throws
"FeedInboundChannelAdapterParserTests-file-usage-context.xml", this.getClass());
latch.await(500, TimeUnit.MILLISECONDS);
verify(latch, times(0)).countDown();
context.destroy();
context.close();
}

@Test
@Ignore // goes against the real feed
public void validateSuccessfulNewsRetrievalWithHttpUrl() throws Exception {
final CountDownLatch latch = new CountDownLatch(3);
MessageHandler handler = spy(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
latch.countDown();
}
});
ApplicationContext context = new ClassPathXmlApplicationContext(
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"FeedInboundChannelAdapterParserTests-http-context.xml", this.getClass());
DirectChannel feedChannel = context.getBean("feedChannel", DirectChannel.class);
feedChannel.subscribe(handler);
latch.await(10, TimeUnit.SECONDS);
verify(handler, atLeast(3)).handleMessage(Mockito.any(Message.class));
context.close();
}

@Test
Expand All @@ -147,7 +150,7 @@ public void testAutoChannel() {
MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class);
SourcePollingChannelAdapter adapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class);
assertSame(autoChannel, TestUtils.getPropertyValue(adapter, "outputChannel"));
context.destroy();
context.close();
}

public static class SampleService {
Expand Down Expand Up @@ -182,9 +185,11 @@ public void receiveFeedEntry(SyndEntry entry) {

public static class SampleMetadataStore implements MetadataStore {

@Override
public void put(String key, String value) {
}

@Override
public String get(String key) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void forwardedToFilters() throws Exception {
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[] { fileMock }));
verify(fileFilterMock1).filterFiles(isA(File[].class));
verify(fileFilterMock2).filterFiles(isA(File[].class));
compositeFileFilter.close();
}

@Test
Expand All @@ -71,6 +72,7 @@ public void forwardedToAddedFilters() throws Exception {
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[] { fileMock }));
verify(fileFilterMock1).filterFiles(isA(File[].class));
verify(fileFilterMock2).filterFiles(isA(File[].class));
compositeFileFilter.close();
}

@Test
Expand All @@ -82,5 +84,6 @@ public void negative() throws Exception {
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
assertTrue(compositeFileFilter.filterFiles(new File[] { fileMock }).isEmpty());
compositeFileFilter.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,11 +28,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.FileCopyUtils;
Expand All @@ -41,6 +40,7 @@
* //INT-2275
*
* @author Artem Bilan
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
Expand All @@ -62,9 +62,6 @@ public class FileOutboundChannelAdapterInsideChainTests {
@Autowired
private MessageChannel outboundChainChannel;

@Autowired
private BeanFactory beanFactory;

private static File workDir;

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,57 +32,58 @@

/**
* @author Mark Fisher
* @author Gary Russell
*/
public class PatternMatchingFileListFilterTests {

@Test
public void matchSingleFile() {
File[] files = new File[]{new File("/some/path/test.txt")};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
}
@Test
public void matchSingleFile() {
File[] files = new File[] { new File("/some/path/test.txt") };
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
}

@Test
public void noMatchWithSingleFile() {
File[] files = new File[]{new File("/some/path/Test.txt")};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(0, accepted.size());
}
@Test
public void noMatchWithSingleFile() {
File[] files = new File[] { new File("/some/path/Test.txt") };
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(0, accepted.size());
}

@Test
public void matchSubset() {
File[] files = new File[]{
new File("/some/path/foo.txt"),
new File("/some/path/foo.not"),
new File("/some/path/bar.txt"),
new File("/some/path/bar.not")
};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(2, accepted.size());
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
}
@Test
public void matchSubset() {
File[] files = new File[] {
new File("/some/path/foo.txt"),
new File("/some/path/foo.not"),
new File("/some/path/bar.txt"),
new File("/some/path/bar.not") };
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(2, accepted.size());
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
}

@Test
@SuppressWarnings("unchecked")
public void patternEditorInContext() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"patternMatchingFileListFilterTests.xml", this.getClass());
FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
File[] files = new File[] { new File("/some/path/foo.txt") };
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
}
@Test
@SuppressWarnings("unchecked")
public void patternEditorInContext() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"patternMatchingFileListFilterTests.xml", this.getClass());
FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
File[] files = new File[] { new File("/some/path/foo.txt") };
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
context.close();
}

@Test(expected = BeanCreationException.class)
public void invalidPatternSyntax() throws Throwable {
new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass());
}
@Test(expected = BeanCreationException.class)
public void invalidPatternSyntax() throws Throwable {
new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass()).close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

<context:property-placeholder location="classpath:org/springframework/integration/file/config/test.properties" />

</beans:beans>
</beans:beans>
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@

package org.springframework.integration.file.config;

import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
*
* @author Gunnar Hillert
* @author Gary Russell
*
*/
public class FileOutboundChannelAdapterParserWithErrorsTests {
Expand All @@ -34,7 +36,8 @@ public class FileOutboundChannelAdapterParserWithErrorsTests {
public void testSettingDirectoryAndDirectoryExpression() {

try {
new ClassPathXmlApplicationContext("FileOutboundChannelAdapterParserWithErrorsTests-context.xml", getClass());
new ClassPathXmlApplicationContext("FileOutboundChannelAdapterParserWithErrorsTests-context.xml",
getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertEquals("Configuration problem: Either directory or " +
Expand All @@ -53,7 +56,8 @@ public void testSettingDirectoryAndDirectoryExpression() {
public void testNotSettingBothDirectoryAndDirectoryExpression() {

try {
new ClassPathXmlApplicationContext("FileOutboundChannelAdapterParserWithErrors2Tests-context.xml", getClass());
new ClassPathXmlApplicationContext("FileOutboundChannelAdapterParserWithErrors2Tests-context.xml",
getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertEquals("Configuration problem: directory or directory-expression " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,9 +67,6 @@ public class FileTailInboundChannelAdapterParserTests {
@Autowired
private TaskScheduler sched;

@Autowired
private TaskScheduler taskScheduler;

@Autowired
private MessageChannel tailErrorChannel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
files.delete=true
files.delete=true
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
inputdir=classpath:
outputdir=classpath:
outputdir=classpath:
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public Integer call() throws Exception {
assertEquals(Integer.valueOf(0), theResult); // lost the race, key changed

file.delete();
filter.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@

<si:poller default="true" fixed-delay="100000000"/>

</beans>
</beans>
Loading

0 comments on commit 8e36227

Please sign in to comment.