@Test public void testGetService() throws Exception { Set<Object> expectedResult = new HashSet<>(asList("1", "2")); new Expectations(Context.class) {{ context.lookupMicroservice(META_DATA); times = 4; result = expectedResult; }}; List<Object> result = new ArrayList<>(); for (int i = 0; i < 4; i++) { result.add(strategy.getService()); } assertThat(result).containsExactly("1", "2", "1", "2"); }
@Override public Object getService() { Set<Object> microservices = context.lookupMicroservice(metaData); if (microservices.isEmpty()) { throw new RuntimeException("No service found for: " + metaData); } Object[] servicesArray = microservices.toArray(); index.compareAndSet(Integer.MAX_VALUE, 0); return servicesArray[index.getAndIncrement() % servicesArray.length]; }
RoundRobinLookupStrategy extends AbstractLookupStrategy { @Override public Object getService() { Set<Object> microservices = context.lookupMicroservice(metaData); if (microservices.isEmpty()) { throw new RuntimeException("No service found for: " + metaData); } Object[] servicesArray = microservices.toArray(); index.compareAndSet(Integer.MAX_VALUE, 0); return servicesArray[index.getAndIncrement() % servicesArray.length]; } }
RoundRobinLookupStrategy extends AbstractLookupStrategy { @Override public Object getService() { Set<Object> microservices = context.lookupMicroservice(metaData); if (microservices.isEmpty()) { throw new RuntimeException("No service found for: " + metaData); } Object[] servicesArray = microservices.toArray(); index.compareAndSet(Integer.MAX_VALUE, 0); return servicesArray[index.getAndIncrement() % servicesArray.length]; }  }
RoundRobinLookupStrategy extends AbstractLookupStrategy { @Override public Object getService() { Set<Object> microservices = context.lookupMicroservice(metaData); if (microservices.isEmpty()) { throw new RuntimeException("No service found for: " + metaData); } Object[] servicesArray = microservices.toArray(); index.compareAndSet(Integer.MAX_VALUE, 0); return servicesArray[index.getAndIncrement() % servicesArray.length]; }  @Override Object getService(); }
RoundRobinLookupStrategy extends AbstractLookupStrategy { @Override public Object getService() { Set<Object> microservices = context.lookupMicroservice(metaData); if (microservices.isEmpty()) { throw new RuntimeException("No service found for: " + metaData); } Object[] servicesArray = microservices.toArray(); index.compareAndSet(Integer.MAX_VALUE, 0); return servicesArray[index.getAndIncrement() % servicesArray.length]; }  @Override Object getService();  }