You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2016/04/18 16:54:18 UTC
[4/5] nifi git commit: NIFI-1654 Using temporary folders via JUnit
for each test within TestProcessorLifecycle
NIFI-1654 Using temporary folders via JUnit for each test within TestProcessorLifecycle
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/a4ef5a1b
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/a4ef5a1b
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/a4ef5a1b
Branch: refs/heads/NIFI-1654
Commit: a4ef5a1badf0ae475acb1ba73867702aa5f89c80
Parents: 729a6cc
Author: Aldrin Piri <al...@apache.org>
Authored: Sat Apr 16 23:58:14 2016 -0400
Committer: Aldrin Piri <al...@apache.org>
Committed: Mon Apr 18 10:42:43 2016 -0400
----------------------------------------------------------------------
.../scheduling/TestProcessorLifecycle.java | 59 +++++++++++---------
1 file changed, 34 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/a4ef5a1b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestProcessorLifecycle.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestProcessorLifecycle.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestProcessorLifecycle.java
index 560c4cb..0fb0da4 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestProcessorLifecycle.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestProcessorLifecycle.java
@@ -63,7 +63,9 @@ import org.apache.nifi.provenance.MockProvenanceEventRepository;
import org.apache.nifi.util.NiFiProperties;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,18 +77,23 @@ public class TestProcessorLifecycle {
private static final Logger logger = LoggerFactory.getLogger(TestProcessorLifecycle.class);
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
@Before
public void before() {
System.setProperty("nifi.properties.file.path", "src/test/resources/nifi.properties");
NiFiProperties.getInstance().setProperty(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
NiFiProperties.getInstance().setProperty(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
NiFiProperties.getInstance().setProperty(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
+ NiFiProperties.getInstance().setProperty(NiFiProperties.FLOWFILE_REPOSITORY_DIRECTORY, temporaryFolder.getRoot().getAbsolutePath() + "/flowfile_repo");
+ NiFiProperties.getInstance().setProperty(NiFiProperties.REPOSITORY_CONTENT_PREFIX + "default", temporaryFolder.getRoot().getAbsolutePath() + "/content_repo");
}
@After
public void after() throws Exception {
- FileUtils.deleteDirectory(new File("./target/test-repo"));
- FileUtils.deleteDirectory(new File("./target/content_repository"));
+ FileUtils.deleteDirectory(new File(temporaryFolder.getRoot().getAbsolutePath() + "/flowfile_repo"));
+ FileUtils.deleteDirectory(new File(temporaryFolder.getRoot().getAbsolutePath() + "/content_repo"));
}
@Test
@@ -95,7 +102,7 @@ public class TestProcessorLifecycle {
ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
this.setControllerRootGroup(fc, testGroup);
final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(),
- UUID.randomUUID().toString());
+ UUID.randomUUID().toString());
assertEquals(ScheduledState.STOPPED, testProcNode.getScheduledState());
assertEquals(ScheduledState.STOPPED, testProcNode.getPhysicalScheduledState());
@@ -118,7 +125,7 @@ public class TestProcessorLifecycle {
ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
this.setControllerRootGroup(fc, testGroup);
final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(),
- UUID.randomUUID().toString());
+ UUID.randomUUID().toString());
testProcNode.setProperty("P", "hello");
assertEquals(ScheduledState.STOPPED, testProcNode.getScheduledState());
assertEquals(ScheduledState.STOPPED, testProcNode.getPhysicalScheduledState());
@@ -640,7 +647,7 @@ public class TestProcessorLifecycle {
properties.setProperty("nifi.remote.input.secure", "");
return FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), properties,
- mock(UserService.class), mock(AuditService.class), null);
+ mock(UserService.class), mock(AuditService.class), null);
}
/**
@@ -677,7 +684,7 @@ public class TestProcessorLifecycle {
private final List<String> operationNames = new LinkedList<>();
void setScenario(Runnable onScheduleCallback, Runnable onUnscheduleCallback, Runnable onStopCallback,
- Runnable onTriggerCallback) {
+ Runnable onTriggerCallback) {
this.onScheduleCallback = onScheduleCallback;
this.onUnscheduleCallback = onUnscheduleCallback;
this.onStopCallback = onStopCallback;
@@ -688,7 +695,7 @@ public class TestProcessorLifecycle {
public void schedule(ProcessContext ctx) {
this.operationNames.add("@OnScheduled");
if (this.generateExceptionOnScheduled
- && this.onScheduledExceptionCount++ < this.keepFailingOnScheduledTimes) {
+ && this.onScheduledExceptionCount++ < this.keepFailingOnScheduledTimes) {
throw new RuntimeException("Intentional");
}
this.onScheduleCallback.run();
@@ -709,26 +716,26 @@ public class TestProcessorLifecycle {
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
PropertyDescriptor PROP = new PropertyDescriptor.Builder()
- .name("P")
- .description("Blah Blah")
- .required(true)
- .addValidator(new Validator() {
- @Override
- public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- return new ValidationResult.Builder().subject(subject).input(value).valid(value != null && !value.isEmpty()).explanation(subject + " cannot be empty").build();
- }
- })
- .build();
+ .name("P")
+ .description("Blah Blah")
+ .required(true)
+ .addValidator(new Validator() {
+ @Override
+ public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
+ return new ValidationResult.Builder().subject(subject).input(value).valid(value != null && !value.isEmpty()).explanation(subject + " cannot be empty").build();
+ }
+ })
+ .build();
PropertyDescriptor SERVICE = new PropertyDescriptor.Builder()
- .name("S")
- .description("Blah Blah")
- .required(true)
- .identifiesControllerService(ITestservice.class)
- .build();
-
- return this.withService ? Arrays.asList(new PropertyDescriptor[] { PROP, SERVICE })
- : Arrays.asList(new PropertyDescriptor[] { PROP });
+ .name("S")
+ .description("Blah Blah")
+ .required(true)
+ .identifiesControllerService(ITestservice.class)
+ .build();
+
+ return this.withService ? Arrays.asList(new PropertyDescriptor[]{PROP, SERVICE})
+ : Arrays.asList(new PropertyDescriptor[]{PROP});
}
@Override
@@ -799,7 +806,9 @@ public class TestProcessorLifecycle {
this.delayLimit = delayLimit;
this.randomDelay = randomDelay;
}
+
Random random = new Random();
+
@Override
public void run() {
try {