@Test public void testQueuedRequestComparator() { List<QueuedRequestWithState> queuedRequestsWithState = Arrays.asList( new QueuedRequestWithState( new QueuedRequestId("serviceA", "requestIdA", 0), new BaragonRequestBuilder().setLoadBalancerRequestId("requestIdA") .setLoadBalancerService(null) .setAddUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setRemoveUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setReplaceUpstreams(Collections.emptyList()) .setAction(Optional.absent()) .setNoValidate(false) .setNoReload(false) .setUpstreamUpdateOnly(false) .setNoDuplicateUpstreams(false) .build(), null ), new QueuedRequestWithState( new QueuedRequestId("serviceB", "requestIdB", 0), new BaragonRequestBuilder().setLoadBalancerRequestId("requestIdB") .setLoadBalancerService(null) .setAddUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setRemoveUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setReplaceUpstreams(Collections.emptyList()) .setAction(Optional.absent()) .setNoValidate(true) .setNoReload(true) .setUpstreamUpdateOnly(false) .setNoDuplicateUpstreams(false) .build(), null ), new QueuedRequestWithState( new QueuedRequestId("serviceC", "requestIdC", 0), new BaragonRequestBuilder().setLoadBalancerRequestId("requestIdC") .setLoadBalancerService(null) .setAddUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setRemoveUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setReplaceUpstreams(Collections.emptyList()) .setAction(Optional.absent()) .setNoValidate(true) .setNoReload(false) .setUpstreamUpdateOnly(false) .setNoDuplicateUpstreams(false) .build(), null ), new QueuedRequestWithState( new QueuedRequestId("serviceC", "requestIdC", 0), new BaragonRequestBuilder().setLoadBalancerRequestId("requestIdC") .setLoadBalancerService(null) .setAddUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setRemoveUpstreams(Collections.singletonList(new UpstreamInfo(null, Optional.absent(), Optional.absent()))) .setReplaceUpstreams(Collections.emptyList()) .setAction(Optional.absent()) .setNoValidate(false) .setNoReload(true) .setUpstreamUpdateOnly(false) .setNoDuplicateUpstreams(false) .build(), null ) ); List<QueuedRequestWithState> sortedQueuedRequestsWithState = new ArrayList<>(queuedRequestsWithState); sortedQueuedRequestsWithState.sort(BaragonRequestWorker.queuedRequestComparator()); assertEquals(queuedRequestsWithState.get(1), sortedQueuedRequestsWithState.get(0)); assertEquals(queuedRequestsWithState.get(0), sortedQueuedRequestsWithState.get(3)); }
@VisibleForTesting static Comparator<QueuedRequestWithState> queuedRequestComparator() { return (requestA, requestB) -> { if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) { return 1; } if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) { return 1; } return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex()); }; }
BaragonRequestWorker implements Runnable { @VisibleForTesting static Comparator<QueuedRequestWithState> queuedRequestComparator() { return (requestA, requestB) -> { if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) { return 1; } if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) { return 1; } return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex()); }; } }
BaragonRequestWorker implements Runnable { @VisibleForTesting static Comparator<QueuedRequestWithState> queuedRequestComparator() { return (requestA, requestB) -> { if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) { return 1; } if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) { return 1; } return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex()); }; } @Inject  BaragonRequestWorker(AgentManager agentManager,
                              RequestManager requestManager,
                              BaragonStateDatastore stateDatastore,
                              BaragonExceptionNotifier exceptionNotifier,
                              BaragonConfiguration configuration,
                              EdgeCache edgeCache,
                              UpstreamResolver resolver,
                              @Named(BaragonDataModule.BARAGON_SERVICE_WORKER_LAST_START) AtomicLong workerLastStartAt); }
BaragonRequestWorker implements Runnable { @VisibleForTesting static Comparator<QueuedRequestWithState> queuedRequestComparator() { return (requestA, requestB) -> { if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) { return 1; } if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) { return 1; } return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex()); }; } @Inject  BaragonRequestWorker(AgentManager agentManager,
                              RequestManager requestManager,
                              BaragonStateDatastore stateDatastore,
                              BaragonExceptionNotifier exceptionNotifier,
                              BaragonConfiguration configuration,
                              EdgeCache edgeCache,
                              UpstreamResolver resolver,
                              @Named(BaragonDataModule.BARAGON_SERVICE_WORKER_LAST_START) AtomicLong workerLastStartAt); @Override void run(); }
BaragonRequestWorker implements Runnable { @VisibleForTesting static Comparator<QueuedRequestWithState> queuedRequestComparator() { return (requestA, requestB) -> { if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) { return 1; } if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) { return -1; } if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) { return 1; } return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex()); }; } @Inject  BaragonRequestWorker(AgentManager agentManager,
                              RequestManager requestManager,
                              BaragonStateDatastore stateDatastore,
                              BaragonExceptionNotifier exceptionNotifier,
                              BaragonConfiguration configuration,
                              EdgeCache edgeCache,
                              UpstreamResolver resolver,
                              @Named(BaragonDataModule.BARAGON_SERVICE_WORKER_LAST_START) AtomicLong workerLastStartAt); @Override void run();  }