use of org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore in project ozone by apache.
the class TestReportPublisher method testCRLStatusReportPublisher.
@Test
public void testCRLStatusReportPublisher() throws IOException {
StateContext dummyContext = Mockito.mock(StateContext.class);
DatanodeStateMachine dummyStateMachine = Mockito.mock(DatanodeStateMachine.class);
ReportPublisher publisher = new CRLStatusReportPublisher();
DatanodeCRLStore dnCrlStore = Mockito.mock(DatanodeCRLStore.class);
when(dnCrlStore.getLatestCRLSequenceID()).thenReturn(3L);
List<CRLInfo> pendingCRLs = new ArrayList<>();
pendingCRLs.add(Mockito.mock(CRLInfo.class));
pendingCRLs.add(Mockito.mock(CRLInfo.class));
when(dnCrlStore.getPendingCRLs()).thenReturn(pendingCRLs);
when(dummyStateMachine.getDnCRLStore()).thenReturn(dnCrlStore);
when(dummyContext.getParent()).thenReturn(dummyStateMachine);
publisher.setConf(config);
ScheduledExecutorService executorService = HadoopExecutors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Unit test ReportManager Thread - %d").build());
publisher.init(dummyContext, executorService);
GeneratedMessage report = ((CRLStatusReportPublisher) publisher).getReport();
Assert.assertNotNull(report);
for (Descriptors.FieldDescriptor descriptor : report.getDescriptorForType().getFields()) {
if (descriptor.getNumber() == CRLStatusReport.RECEIVEDCRLID_FIELD_NUMBER) {
Assert.assertEquals(3L, report.getField(descriptor));
}
}
executorService.shutdown();
}
use of org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore in project ozone by apache.
the class CRLStatusReportPublisher method getReport.
@Override
protected CRLStatusReport getReport() throws IOException {
CRLStatusReport.Builder builder = CRLStatusReport.newBuilder();
DatanodeCRLStore dnCRLStore = this.getContext().getParent().getDnCRLStore();
builder.setReceivedCrlId(dnCRLStore.getLatestCRLSequenceID());
if (dnCRLStore.getPendingCRLs().size() > 0) {
List<Long> pendingCRLIds = dnCRLStore.getPendingCRLs().stream().map(CRLInfo::getCrlSequenceID).collect(Collectors.toList());
builder.addAllPendingCrlIds(pendingCRLIds);
}
return builder.build();
}
Aggregations