use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.
the class DiscoveryHelperProviderTest method provider.
@Test
public void provider() {
try (var mockedEnclave = mockStatic(Enclave.class);
var mockedNetworkStore = mockStatic(NetworkStore.class)) {
NetworkStore networkStore = mock(NetworkStore.class);
mockedNetworkStore.when(NetworkStore::getInstance).thenReturn(networkStore);
Enclave enclave = mock(Enclave.class);
mockedEnclave.when(Enclave::create).thenReturn(enclave);
DiscoveryHelper helper = DiscoveryHelperProvider.provider();
assertThat(helper).isNotNull().isExactlyInstanceOf(DiscoveryHelperImpl.class);
mockedEnclave.verify(Enclave::create);
mockedEnclave.verifyNoMoreInteractions();
mockedNetworkStore.verify(NetworkStore::getInstance);
mockedNetworkStore.verifyNoMoreInteractions();
verifyNoInteractions(networkStore);
verifyNoInteractions(enclave);
}
}
use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildCurrent.
@Test
public void buildCurrent() {
final URI uri = URI.create("http://somedomain.com");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
final List<PublicKey> keys = IntStream.range(0, 5).mapToObj(i -> mock(PublicKey.class)).collect(Collectors.toList());
final ActiveNode activeNode = ActiveNode.Builder.create().withUri(NodeUri.create(uri)).withKeys(keys).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
NodeInfo result = discoveryHelper.buildCurrent();
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
assertThat(result.getRecipients()).hasSize(5);
List<Recipient> recipients = List.copyOf(result.getRecipients());
assertThat(recipients.stream().map(Recipient::getKey).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(keys);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildAllNodeInfos.
@Test
public void buildAllNodeInfos() {
when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://own.com"));
final ActiveNode node1 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node1.com")).withKeys(List.of(PublicKey.from("key1".getBytes()))).withSupportedVersions(List.of("v1")).build();
final ActiveNode node2 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node2.com")).withKeys(List.of(PublicKey.from("key2".getBytes()))).withSupportedVersions(List.of("v2")).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(node1, node2));
final Set<NodeInfo> nodeInfos = discoveryHelper.buildRemoteNodeInfos();
assertThat(nodeInfos).hasSize(2);
Set<ActiveNode> activeNodes = nodeInfos.stream().map(nodeInfo -> ActiveNode.Builder.create().withUri(NodeUri.create(nodeInfo.getUrl())).withKeys(nodeInfo.getRecipients().stream().map(Recipient::getKey).collect(Collectors.toSet())).withSupportedVersions(nodeInfo.supportedApiVersions()).build()).collect(Collectors.toSet());
assertThat(activeNodes).containsExactlyInAnyOrder(node1, node2);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.
the class DiscoveryProvider method provider.
/**
* @see java.util.ServiceLoader.Provider
*/
public static Discovery provider() {
final DiscoveryHolder discoveryHolder = DiscoveryHolder.create();
if (discoveryHolder.get().isPresent()) {
return discoveryHolder.get().get();
}
final NetworkStore networkStore = NetworkStore.getInstance();
final RuntimeContext runtimeContext = RuntimeContext.getInstance();
final Discovery discovery;
if (runtimeContext.isDisablePeerDiscovery()) {
final Set<NodeUri> knownNodes = runtimeContext.getPeers().stream().map(NodeUri::create).collect(Collectors.toUnmodifiableSet());
discovery = new DisabledAutoDiscovery(networkStore, knownNodes);
} else {
discovery = new AutoDiscovery(networkStore);
}
discoveryHolder.set(discovery);
return discovery;
}
use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.
the class EnclaveKeySynchroniserProviderTest method provider.
@Test
public void provider() {
try (var mockedEnclave = mockStatic(Enclave.class);
var mockedNetworkStore = mockStatic(NetworkStore.class)) {
NetworkStore networkStore = mock(NetworkStore.class);
mockedNetworkStore.when(NetworkStore::getInstance).thenReturn(networkStore);
Enclave enclave = mock(Enclave.class);
mockedEnclave.when(Enclave::create).thenReturn(enclave);
EnclaveKeySynchroniser enclaveKeySynchroniser = EnclaveKeySynchroniserProvider.provider();
assertThat(enclaveKeySynchroniser).isNotNull().isExactlyInstanceOf(EnclaveKeySynchroniserImpl.class);
mockedEnclave.verify(Enclave::create);
mockedEnclave.verifyNoMoreInteractions();
mockedNetworkStore.verify(NetworkStore::getInstance);
mockedNetworkStore.verifyNoMoreInteractions();
verifyNoInteractions(networkStore);
verifyNoInteractions(enclave);
}
}
Aggregations