Datanode periodical for NodeService pings (#15003)

* Datanode periodical for NodeService pings

* node service markAsAlive update without additional query

* added unit test for NodePingPeriodical

* code cleanup

* simplified NodePingPeriodicalTest
This commit is contained in:
Tomas Dvorak
2023-03-23 09:02:35 +01:00
committed by GitHub
parent 2881b8dce2
commit 3f4dad6a7b
10 changed files with 235 additions and 22 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog.datanode.periodicals;
import org.graylog2.cluster.NodeNotFoundException;
import org.graylog2.cluster.NodeService;
import org.graylog2.plugin.system.SimpleNodeId;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.net.URI;
class NodePingPeriodicalTest {
@Test
void doRun() throws NodeNotFoundException {
final SimpleNodeId nodeID = new SimpleNodeId("5ca1ab1e-0000-4000-a000-000000000000");
final URI uri = URI.create("http://localhost:8999");
final NodeService nodeService = Mockito.mock(NodeService.class);
final NodePingPeriodical task = new NodePingPeriodical(
nodeService,
nodeID,
uri,
() -> true
);
task.doRun();
Mockito.verify(nodeService).markAsAlive(
Mockito.eq(nodeID),
Mockito.eq(true),
Mockito.eq(uri));
}
@Test
void doRunWithRegister() throws NodeNotFoundException {
final SimpleNodeId nodeID = new SimpleNodeId("5ca1ab1e-0000-4000-a000-000000000000");
final URI uri = URI.create("http://localhost:8999");
final NodeService nodeService = Mockito.mock(NodeService.class);
Mockito.doThrow(new NodeNotFoundException("Node not found")).when(nodeService).markAsAlive(nodeID, true, uri);
final NodePingPeriodical task = new NodePingPeriodical(
nodeService,
nodeID,
uri,
() -> true
);
task.doRun();
Mockito.verify(nodeService).registerServer(
Mockito.eq(nodeID.getNodeId()),
Mockito.eq(true),
Mockito.eq(uri),
Mockito.any()
);
}
}