@Test public void testGetCloudDataNode() throws NoSuchFieldException, ReplicationException { CloudToStoreReplicationManager mockCloudToStoreReplicationManager = mock(CloudToStoreReplicationManager.class); List<DataNodeId> dataNodeIds = new ArrayList<>(); Port port = new Port(1000, PortType.PLAINTEXT); AtomicReference<List<DataNodeId>> vcrNodes = new AtomicReference<>(); vcrNodes.set(dataNodeIds); FieldSetter.setField(mockCloudToStoreReplicationManager, CloudToStoreReplicationManager.class.getDeclaredField("vcrNodes"), vcrNodes); when(mockCloudToStoreReplicationManager.getCloudDataNode()).thenCallRealMethod(); try { mockCloudToStoreReplicationManager.getCloudDataNode(); fail("Calling getCloudDataNode when there are no vcrNodes should throw exception."); } catch (ReplicationException rex) { } for (int i = 0; i < 100; i++) { dataNodeIds.add(new MockDataNodeId("hosname" + i, Collections.singletonList(port), null, null)); } try { Set<String> dataNodeIdSet = new HashSet<>(); for (int i = 0; i < 5; i++) { dataNodeIdSet.add(mockCloudToStoreReplicationManager.getCloudDataNode().getHostname()); } assertTrue("getCloudDataNode shouldn't return same node every time", dataNodeIdSet.size() > 1); } catch (ReplicationException rex) { fail("getCloudDataNode shouldn't fail if vcrNodes is not empty"); } }
DataNodeId getCloudDataNode() throws ReplicationException { List<CloudDataNode> nodes = vcrNodes.get(); if (nodes.isEmpty()) { throw new ReplicationException("No VCR node found to replicate partition from cloud."); } return nodes.get(Utils.getRandomShort(random) % nodes.size()); }
CloudToStoreReplicationManager extends ReplicationEngine { DataNodeId getCloudDataNode() throws ReplicationException { List<CloudDataNode> nodes = vcrNodes.get(); if (nodes.isEmpty()) { throw new ReplicationException("No VCR node found to replicate partition from cloud."); } return nodes.get(Utils.getRandomShort(random) % nodes.size()); } }
CloudToStoreReplicationManager extends ReplicationEngine { DataNodeId getCloudDataNode() throws ReplicationException { List<CloudDataNode> nodes = vcrNodes.get(); if (nodes.isEmpty()) { throw new ReplicationException("No VCR node found to replicate partition from cloud."); } return nodes.get(Utils.getRandomShort(random) % nodes.size()); } CloudToStoreReplicationManager(ReplicationConfig replicationConfig, ClusterMapConfig clusterMapConfig,
      StoreConfig storeConfig, StoreManager storeManager, StoreKeyFactory storeKeyFactory, ClusterMap clusterMap,
      ScheduledExecutorService scheduler, DataNodeId currentNode, ConnectionPool connectionPool,
      MetricRegistry metricRegistry, NotificationSystem requestNotification,
      StoreKeyConverterFactory storeKeyConverterFactory, String transformerClassName,
      ClusterSpectator vcrClusterSpectator, ClusterParticipant clusterParticipant); }
CloudToStoreReplicationManager extends ReplicationEngine { DataNodeId getCloudDataNode() throws ReplicationException { List<CloudDataNode> nodes = vcrNodes.get(); if (nodes.isEmpty()) { throw new ReplicationException("No VCR node found to replicate partition from cloud."); } return nodes.get(Utils.getRandomShort(random) % nodes.size()); } CloudToStoreReplicationManager(ReplicationConfig replicationConfig, ClusterMapConfig clusterMapConfig,
      StoreConfig storeConfig, StoreManager storeManager, StoreKeyFactory storeKeyFactory, ClusterMap clusterMap,
      ScheduledExecutorService scheduler, DataNodeId currentNode, ConnectionPool connectionPool,
      MetricRegistry metricRegistry, NotificationSystem requestNotification,
      StoreKeyConverterFactory storeKeyConverterFactory, String transformerClassName,
      ClusterSpectator vcrClusterSpectator, ClusterParticipant clusterParticipant); @Override void start(); }
CloudToStoreReplicationManager extends ReplicationEngine { DataNodeId getCloudDataNode() throws ReplicationException { List<CloudDataNode> nodes = vcrNodes.get(); if (nodes.isEmpty()) { throw new ReplicationException("No VCR node found to replicate partition from cloud."); } return nodes.get(Utils.getRandomShort(random) % nodes.size()); } CloudToStoreReplicationManager(ReplicationConfig replicationConfig, ClusterMapConfig clusterMapConfig,
      StoreConfig storeConfig, StoreManager storeManager, StoreKeyFactory storeKeyFactory, ClusterMap clusterMap,
      ScheduledExecutorService scheduler, DataNodeId currentNode, ConnectionPool connectionPool,
      MetricRegistry metricRegistry, NotificationSystem requestNotification,
      StoreKeyConverterFactory storeKeyConverterFactory, String transformerClassName,
      ClusterSpectator vcrClusterSpectator, ClusterParticipant clusterParticipant); @Override void start();  }