mirror of https://github.com/apache/nifi.git
NIFI-1872: Allow sufficient time for embedded server to startup for unit tests
This commit is contained in:
parent
707aeb4231
commit
87d96c0225
|
@ -17,6 +17,12 @@
|
||||||
|
|
||||||
package org.apache.nifi.controller.state.providers.zookeeper;
|
package org.apache.nifi.controller.state.providers.zookeeper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
|
||||||
import org.apache.curator.test.TestingServer;
|
import org.apache.curator.test.TestingServer;
|
||||||
import org.apache.nifi.attribute.expression.language.StandardPropertyValue;
|
import org.apache.nifi.attribute.expression.language.StandardPropertyValue;
|
||||||
import org.apache.nifi.components.PropertyDescriptor;
|
import org.apache.nifi.components.PropertyDescriptor;
|
||||||
|
@ -27,15 +33,9 @@ import org.apache.nifi.components.state.exception.StateTooLargeException;
|
||||||
import org.apache.nifi.controller.state.providers.AbstractTestStateProvider;
|
import org.apache.nifi.controller.state.providers.AbstractTestStateProvider;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
|
public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
|
||||||
|
|
||||||
private StateProvider provider;
|
private StateProvider provider;
|
||||||
|
@ -117,9 +117,8 @@ public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test(timeout = 20000)
|
||||||
@Ignore("Needs to be fixed as it intermittently fails.")
|
public void testStateTooLargeExceptionThrownOnSetState() throws InterruptedException {
|
||||||
public void testStateTooLargeExceptionThrownOnSetState() {
|
|
||||||
final Map<String, String> state = new HashMap<>();
|
final Map<String, String> state = new HashMap<>();
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
@ -133,21 +132,29 @@ public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
|
||||||
state.put("numbers." + i, sb.toString());
|
state.put("numbers." + i, sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
while (true) {
|
||||||
getProvider().setState(state, componentId);
|
try {
|
||||||
Assert.fail("Expected StateTooLargeException");
|
getProvider().setState(state, componentId);
|
||||||
} catch (final StateTooLargeException stle) {
|
Assert.fail("Expected StateTooLargeException");
|
||||||
// expected behavior.
|
} catch (final StateTooLargeException stle) {
|
||||||
} catch (final Exception e) {
|
// expected behavior.
|
||||||
e.printStackTrace();
|
break;
|
||||||
Assert.fail("Expected StateTooLargeException but " + e.getClass() + " was thrown", e);
|
} catch (final IOException ioe) {
|
||||||
|
// If we attempt to interact with the server too quickly, we will get a
|
||||||
|
// ZooKeeper ConnectionLoss Exception, which the provider wraps in an IOException.
|
||||||
|
// We will wait 1 second in this case and try again. The test will timeout if this
|
||||||
|
// does not succeeed within 20 seconds.
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail("Expected StateTooLargeException but " + e.getClass() + " was thrown", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test(timeout = 20000)
|
||||||
@Ignore("Needs to be fixed as it intermittently fails.")
|
public void testStateTooLargeExceptionThrownOnReplace() throws IOException, InterruptedException {
|
||||||
public void testStateTooLargeExceptionThrownOnReplace() throws IOException {
|
|
||||||
final Map<String, String> state = new HashMap<>();
|
final Map<String, String> state = new HashMap<>();
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
@ -163,7 +170,19 @@ public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
|
||||||
|
|
||||||
final Map<String, String> smallState = new HashMap<>();
|
final Map<String, String> smallState = new HashMap<>();
|
||||||
smallState.put("abc", "xyz");
|
smallState.put("abc", "xyz");
|
||||||
getProvider().setState(smallState, componentId);
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
getProvider().setState(smallState, componentId);
|
||||||
|
break;
|
||||||
|
} catch (final IOException ioe) {
|
||||||
|
// If we attempt to interact with the server too quickly, we will get a
|
||||||
|
// ZooKeeper ConnectionLoss Exception, which the provider wraps in an IOException.
|
||||||
|
// We will wait 1 second in this case and try again. The test will timeout if this
|
||||||
|
// does not succeeed within 20 seconds.
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getProvider().replace(getProvider().getState(componentId), state, componentId);
|
getProvider().replace(getProvider().getState(componentId), state, componentId);
|
||||||
|
|
Loading…
Reference in New Issue