@Override
    public long selectNextWorker() throws NonRecoverableException {
        ComputeNode worker;
        if (usedComputeNode) {
            worker = getNextWorker(availableID2ComputeNode, DefaultWorkerProvider::getNextComputeNodeIndex);
        } else {
            worker = getNextWorker(availableID2Backend, DefaultWorkerProvider::getNextBackendIndex);
        }

        if (worker == null) {
            reportWorkerNotFoundException();
        }
        Preconditions.checkNotNull(worker);

        selectWorkerUnchecked(worker.getId());
        return worker.getId();
    }
@Test
    public void testSelectNextWorker() throws UserException {
        DefaultWorkerProvider workerProvider;

        workerProvider =
                new DefaultWorkerProvider(id2Backend, id2ComputeNode, availableId2Backend, availableId2ComputeNode,
                        true);
        testSelectNextWorkerHelper(workerProvider, availableId2ComputeNode);

        workerProvider =
                new DefaultWorkerProvider(id2Backend, id2ComputeNode, availableId2Backend, ImmutableMap.of(), true);
        testSelectNextWorkerHelper(workerProvider, availableId2Backend);

        workerProvider =
                new DefaultWorkerProvider(id2Backend, id2ComputeNode, availableId2Backend, availableId2ComputeNode,
                        false);
        testSelectNextWorkerHelper(workerProvider, availableId2Backend);

        workerProvider =
                new DefaultWorkerProvider(id2Backend, id2ComputeNode, ImmutableMap.of(), ImmutableMap.of(), false);
        DefaultWorkerProvider finalWorkerProvider = workerProvider;
        Assert.assertThrows(SchedulerException.class, finalWorkerProvider::selectNextWorker);
    }