Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IKASAN-2062] Try and make SftpToJmsFlowTest pass every time #1054

Merged
merged 2 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,14 @@ public void scheduleAsEagerTrigger(Trigger oldTrigger, int eagerCallback) throws
{
try
{
Date triggerStartTime = new Date(System.currentTimeMillis() + 1000);

TriggerBuilder oldTriggerBuilder = oldTrigger.getTriggerBuilder();
Trigger newTrigger = oldTriggerBuilder.usingJobData(EAGER_CALLBACK_COUNT, eagerCallback).
startNow().
withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow()).build();
Trigger newTrigger = oldTriggerBuilder.usingJobData(EAGER_CALLBACK_COUNT, eagerCallback)
.startAt(triggerStartTime)
.withSchedule(simpleSchedule()
.withMisfireHandlingInstructionFireNow())
.build();

Date scheduledDate;
if(this.scheduler.checkExists(oldTrigger.getKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ public void test_execute_when_messageProvider_returns_true_and_not_in_recovery_a
exactly(1).of(trigger).getTriggerBuilder();
will(returnValue(triggerBuilder));

exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", new Integer(1));
exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", 1);
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).startNow();
exactly(1).of(triggerBuilder).startAt(with(any(Date.class)));
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).withSchedule(with(any(ScheduleBuilder.class)));

Expand Down Expand Up @@ -476,9 +476,9 @@ public void test_execute_when_messageProvider_returns_true_and_not_in_recovery_a
exactly(1).of(trigger).getTriggerBuilder();
will(returnValue(triggerBuilder));

exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", new Integer(1));
exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", 1);
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).startNow();
exactly(1).of(triggerBuilder).startAt(with(any(Date.class)));
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).withSchedule(with(any(ScheduleBuilder.class)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ public void test_execute_when_messageProvider_message_is_not_null_and_consumer_i
{
final FlowEvent mockFlowEvent = mockery.mock( FlowEvent.class);
final String identifier = "testId";
final JobKey jobKey = new JobKey("flowName", "moduleName");
final JobDetail jobDetail = mockery.mock(JobDetail.class);
final TriggerKey triggerKey = new TriggerKey("flowName","moduleName");
final JobDataMap jobDataMap = new JobDataMap();
Expand Down Expand Up @@ -566,9 +565,9 @@ public void test_execute_when_messageProvider_message_is_not_null_and_consumer_i
exactly(1).of(trigger).getTriggerBuilder();
will(returnValue(triggerBuilder));

exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", new Integer(1));
exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", 1);
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).startNow();
exactly(1).of(triggerBuilder).startAt(with(any(Date.class)));
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).withSchedule(with(any(ScheduleBuilder.class)));

Expand Down Expand Up @@ -633,9 +632,9 @@ public void test_execute_when_messageProvider_message_is_not_null_and_consumer_i
exactly(1).of(trigger).getTriggerBuilder();
will(returnValue(triggerBuilder));

exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", new Integer(1));
exactly(1).of(triggerBuilder).usingJobData("eagerCallbackCount", 1);
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).startNow();
exactly(1).of(triggerBuilder).startAt(with(any(Date.class)));
will(returnValue(triggerBuilder));
exactly(1).of(triggerBuilder).withSchedule(with(any(ScheduleBuilder.class)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
package com.ikasan.sample.spring.boot.builderpattern;

import com.github.stefanbirkner.fakesftpserver.rule.FakeSftpServerRule;

import org.ikasan.endpoint.sftp.consumer.SftpConsumerConfiguration;
import org.ikasan.nonfunctional.test.util.FileTestUtil;
import org.ikasan.spec.flow.Flow;
Expand All @@ -47,7 +48,6 @@
import org.ikasan.testharness.flow.jms.ActiveMqHelper;
import org.ikasan.testharness.flow.jms.MessageListenerVerifier;
import org.ikasan.testharness.flow.rule.IkasanFlowTestRule;
import org.ikasan.testharness.flow.sftp.SftpRule;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -57,7 +57,6 @@
import org.springframework.jms.config.JmsListenerEndpointRegistry;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.SocketUtils;

import javax.annotation.Resource;
import javax.sql.DataSource;
Expand All @@ -81,8 +80,7 @@
@SpringBootTest(classes = {Application.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class SftpToJmsFlowTest
{
public class SftpToJmsFlowTest {

private static String SAMPLE_MESSAGE = "Hello world!";

Expand All @@ -102,29 +100,28 @@ public class SftpToJmsFlowTest

String objectStoreDir = "./transaction-logs";

public IkasanFlowTestRule flowTestRule = new IkasanFlowTestRule( );
public IkasanFlowTestRule flowTestRule = new IkasanFlowTestRule();

@Rule
public FakeSftpServerRule sftp = new FakeSftpServerRule().addUser("test", "test");

public MessageListenerVerifier messageListenerVerifier;

@Before
public void setup() throws IOException
{
public void setup() throws IOException {
FileTestUtil.deleteFile(new File(objectStoreDir));
sftp.createDirectories("/source");
messageListenerVerifier = new MessageListenerVerifier(brokerUrl, "sftp.private.jms.queue", registry);
messageListenerVerifier.start();
flowTestRule.withFlow(moduleUnderTest.getFlow("Sftp To Jms Flow"));
}

@After public void teardown() throws SQLException, IOException
{
@After
public void teardown() throws SQLException, IOException {
messageListenerVerifier.stop();
sftp.deleteAllFilesAndDirectories();
String currentState = flowTestRule.getFlowState();
if (currentState.equals(RECOVERING) || currentState.equals(RUNNING)){
if (currentState.equals(RECOVERING) || currentState.equals(RUNNING)) {
flowTestRule.stopFlow();
}
new ActiveMqHelper().removeAllMessages();
Expand All @@ -133,39 +130,33 @@ public void setup() throws IOException
}

@AfterClass
public static void shutdownBroker(){
public static void shutdownBroker() {
new ActiveMqHelper().shutdownBroker();
}

@Test
public void test_file_download() throws Exception
{
public void test_file_download() throws Exception {

// Upload data to fake SFTP
sftp.putFile("/source/testDownload.txt",SAMPLE_MESSAGE, Charset.defaultCharset());
sftp.putFile("/source/testDownload.txt", SAMPLE_MESSAGE, Charset.defaultCharset());

//Update Sftp Consumer config
SftpConsumerConfiguration consumerConfiguration = flowTestRule.getComponentConfig("Sftp Consumer",SftpConsumerConfiguration.class);
// Update Sftp Consumer config
SftpConsumerConfiguration consumerConfiguration = flowTestRule.getComponentConfig("Sftp Consumer", SftpConsumerConfiguration.class);
consumerConfiguration.setSourceDirectory("/source");
consumerConfiguration.setRemotePort(sftp.getPort());

//Setup component expectations

// Setup component expectations
flowTestRule.consumer("Sftp Consumer")
.converter("Sftp Payload to Map Converter")
.producer("Sftp Jms Producer");

// start the flow and assert it runs
flowTestRule.startFlow();
with().pollInterval(500, TimeUnit.MILLISECONDS).and().await().atMost(60, TimeUnit.SECONDS)
.untilAsserted(() -> assertEquals("running",flowTestRule.getFlowState()));

flowTestRule.fireScheduledConsumer();

with().pollInterval(500, TimeUnit.MILLISECONDS).and().await().atMost(60, TimeUnit.SECONDS)
.untilAsserted(() -> assertEquals(1, messageListenerVerifier.getCaptureResults().size() ));
with().pollInterval(500, TimeUnit.MILLISECONDS).and().await().atMost(30, TimeUnit.SECONDS)
.untilAsserted(() -> assertEquals(1, messageListenerVerifier.getCaptureResults().size()));
flowTestRule.assertIsSatisfied();

}

}