use of co.cask.cdap.gateway.discovery.VersionFilteredServiceDiscovered in project cdap by caskdata.
the class VersionFilteredServiceDiscoveredTest method testVersion.
@Test
public void testVersion() throws Exception {
ProgramId serviceId = new ApplicationId("n1", "a1").service("s1");
String discoverableName = ServiceDiscoverable.getName(serviceId);
List<Discoverable> candidates = new ArrayList<>();
for (int i = 0; i < 5; i++) {
candidates.add(new Discoverable(discoverableName, null, Bytes.toBytes(Integer.toString(i))));
candidates.add(new Discoverable(discoverableName, null, Bytes.toBytes(Integer.toString(i))));
}
SimpleServiceDiscovered serviceDiscovered = new SimpleServiceDiscovered(candidates);
// With '1' as the filter, only that version should be returned
VersionFilteredServiceDiscovered filteredServiceDiscovered = new VersionFilteredServiceDiscovered(serviceDiscovered, "1");
Iterator<Discoverable> filteredIterator = filteredServiceDiscovered.iterator();
while (filteredIterator.hasNext()) {
Assert.assertArrayEquals("1".getBytes(), filteredIterator.next().getPayload());
}
// With null, all the versions should be returned
filteredServiceDiscovered = new VersionFilteredServiceDiscovered(serviceDiscovered, null);
filteredIterator = filteredServiceDiscovered.iterator();
Set<String> versions = new HashSet<>();
while (filteredIterator.hasNext()) {
versions.add(Bytes.toString(filteredIterator.next().getPayload()));
}
Assert.assertTrue(versions.size() == 5);
}
Aggregations