Github user olegz commented on the pull request:
https://github.com/apache/nifi/pull/347#issuecomment-217000289
@pvillard31 below is the test you can use to validate this issue. Basically
if you execute it on current master it will fail the assertions and then with
your changes it will succeed.
Also keep in mind that you would need a second PR (one as an update to this
one and another for 0.x branch that is essentially 0.7.0-SNAPSHOT). The reason
being is that _UserService_ was migrated to _KeyService_ so the test below
won't compile on 0.x where you still have to use UserService. I am sure you'll
figure it out. Also, feel free to change the test class/method names to be more
reflective what's being tested.
Cheers
```java
package org.apache.nifi.controller;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import java.net.URL;
import java.util.Collections;
import org.apache.nifi.admin.service.AuditService;
import org.apache.nifi.admin.service.KeyService;
import org.apache.nifi.controller.repository.RepositoryStatusReport;
import org.apache.nifi.controller.repository.RingBufferEventRepository;
import org.apache.nifi.controller.repository.StandardFlowFileEvent;
import org.apache.nifi.controller.repository.StandardRepositoryStatusReport;
import org.apache.nifi.controller.status.ProcessGroupStatus;
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.groups.RemoteProcessGroup;
import org.apache.nifi.groups.RemoteProcessGroupPortDescriptor;
import org.apache.nifi.provenance.MockProvenanceEventRepository;
import org.apache.nifi.remote.RemoteGroupPort;
import org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor;
import org.apache.nifi.util.NiFiProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class RPGStatusTest {
private final KeyService userService = mock(KeyService.class);
private final AuditService auditService = mock(AuditService.class);
private volatile FlowController controller;
@BeforeClass
public static void beforeClass() {
try {
URL url =
ClassLoader.getSystemClassLoader().getResource("nifi.properties");
System.setProperty("nifi.properties.file.path", url.getFile());
} catch (Exception e) {
throw new IllegalStateException("Failed to discover
nifi.properties at the root of the classpath", e);
}
}
@Before
public void before() {
NiFiProperties properties = NiFiProperties.getInstance();
properties.setProperty(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS,
MockProvenanceEventRepository.class.getName());
properties.setProperty(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE,
"src/test/resources/state-management.xml");
properties.setProperty(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID,
"local-provider");
properties.setProperty(NiFiProperties.REMOTE_INPUT_HOST,
"localhost");
properties.setProperty("nifi.remote.input.secure", "false");
RingBufferEventRepository repository = new
RingBufferEventRepository(1);
this.controller =
FlowController.createStandaloneInstance(repository,
NiFiProperties.getInstance(),
this.userService, this.auditService, null);
}
@After
public void after() {
this.controller.shutdown(false);
}
@Test
public void testPr347() throws Exception {
ProcessGroup receiverGroup = controller.createProcessGroup("SITE");
NiFiTestUtils.setControllerRootGroup(this.controller,
receiverGroup);
RemoteProcessGroup remoteProcessGroup =
controller.createRemoteProcessGroup("SENDER_REMOTE","http://foo:1234/nifi");
receiverGroup.addRemoteProcessGroup(remoteProcessGroup);
String inputPortId = "inputId";
StandardRemoteProcessGroupPortDescriptor inputPortDescriptor = new
StandardRemoteProcessGroupPortDescriptor();
inputPortDescriptor.setId(inputPortId);
inputPortDescriptor.setName("inputPort");
remoteProcessGroup.setInputPorts(Collections.<RemoteProcessGroupPortDescriptor>
singleton(inputPortDescriptor));
RemoteGroupPort inputPort =
remoteProcessGroup.getInputPort(inputPortId);
inputPort.setProcessGroup(receiverGroup);
String outputPortId = "outputId";
StandardRemoteProcessGroupPortDescriptor outputPortDescriptor = new
StandardRemoteProcessGroupPortDescriptor();
outputPortDescriptor.setId(outputPortId);
outputPortDescriptor.setName("outputPport");
remoteProcessGroup.setOutputPorts(Collections.<RemoteProcessGroupPortDescriptor>
singleton(outputPortDescriptor));
RemoteGroupPort outputPort =
remoteProcessGroup.getOutputPort(outputPortId);
outputPort.setProcessGroup(receiverGroup);
RepositoryStatusReport rp = new StandardRepositoryStatusReport();
StandardFlowFileEvent inputEvent = new
StandardFlowFileEvent(inputPortId);
inputEvent.setBytesSent(1234);
rp.addReportEntry(inputEvent);
StandardFlowFileEvent outputEvent = new
StandardFlowFileEvent(outputPortId);
outputEvent.setFlowFilesReceived(45);
rp.addReportEntry(outputEvent);
ProcessGroupStatus status =
controller.getGroupStatus(receiverGroup, rp);
assertEquals(0, status.getFlowFilesReceived());
assertEquals(0, status.getBytesSent());
}
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---