Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public class MoverRequestScheduler {

public long numberOfRequestsFor(PnfsId pnfsId) {
return _jobs.values().stream()
.filter((pr) -> pr.getMover().getFileAttributes().getPnfsId().equals(pnfsId)).count();
.filter((pr) -> pr.getMover().getFileAttributes().getPnfsId().equals(pnfsId))
.filter((pr) -> !pr.getMover().isPoolToPoolTransfer())
.count();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.dcache.pool.classic;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import diskCacheV111.util.PnfsId;
import org.dcache.pool.movers.Mover;
import org.dcache.util.IoPriority;
import org.dcache.vehicles.FileAttributes;
import org.junit.Before;
import org.junit.Test;

public class IoQueueManagerTest {

private IoQueueManager ioQueueManager;
private PnfsId pnfsId = new PnfsId("000000000000000000000000000000000001");

@Before
public void setUp() {
ioQueueManager = new IoQueueManager();
}

@Test
public void shouldSumRequestsAcrossQueuesExcludingP2P() throws Exception {
// Add a regular mover to the default queue
addMover(IoQueueManager.DEFAULT_QUEUE, false);

// Add a P2P mover to the p2p queue
addMover(IoQueueManager.P2P_QUEUE_NAME, true);

// Add another regular mover to a custom queue
ioQueueManager.setQueues(new String[]{"custom"});
addMover("custom", false);

// Total should be 2 (1 from default, 1 from custom, 0 from p2p)
assertEquals(2, ioQueueManager.numberOfRequestsFor(pnfsId));
}

private void addMover(String queueName, boolean isP2P) throws Exception {
Mover mover = mock(Mover.class);
FileAttributes attributes = new FileAttributes();
attributes.setPnfsId(pnfsId);
when(mover.getFileAttributes()).thenReturn(attributes);
when(mover.isPoolToPoolTransfer()).thenReturn(isP2P);

MoverSupplier supplier = mock(MoverSupplier.class);
when(supplier.createMover()).thenReturn(mover);

ioQueueManager.getOrCreateMover(queueName, "door-" + queueName + "-" + System.nanoTime(), supplier, IoPriority.REGULAR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.dcache.pool.classic;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import diskCacheV111.util.PnfsId;
import org.dcache.pool.movers.Mover;
import org.dcache.util.IoPriority;
import org.dcache.vehicles.FileAttributes;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an unused import (java.util.concurrent.atomic.AtomicInteger) in this new test file. Java treats unused imports as compilation errors, so it must be removed.

Suggested change
import java.util.concurrent.atomic.AtomicInteger;

Copilot uses AI. Check for mistakes.

public class MoverRequestSchedulerTest {

private MoverRequestScheduler scheduler;
private PnfsId pnfsId = new PnfsId("000000000000000000000000000000000001");

@Before
public void setUp() {
scheduler = new MoverRequestScheduler("test-queue", 0, MoverRequestScheduler.Order.FIFO);
}

@Test
public void shouldCountNonP2PRequests() throws Exception {
addMover(pnfsId, false);
addMover(pnfsId, false);

assertEquals(2, scheduler.numberOfRequestsFor(pnfsId));
}

@Test
public void shouldNotCountP2PRequests() throws Exception {
addMover(pnfsId, true);
addMover(pnfsId, false);

assertEquals(1, scheduler.numberOfRequestsFor(pnfsId));
}

@Test
public void shouldReturnZeroWhenNoRequests() {
assertEquals(0, scheduler.numberOfRequestsFor(pnfsId));
}

@Test
public void shouldNotCountRequestsForDifferentPnfsId() throws Exception {
PnfsId otherPnfsId = new PnfsId("000000000000000000000000000000000002");
addMover(otherPnfsId, false);

assertEquals(0, scheduler.numberOfRequestsFor(pnfsId));
}

private void addMover(PnfsId pnfsId, boolean isP2P) throws Exception {
Mover mover = mock(Mover.class);
FileAttributes attributes = new FileAttributes();
attributes.setPnfsId(pnfsId);
when(mover.getFileAttributes()).thenReturn(attributes);
when(mover.isPoolToPoolTransfer()).thenReturn(isP2P);

MoverSupplier supplier = mock(MoverSupplier.class);
when(supplier.createMover()).thenReturn(mover);

scheduler.getOrCreateMover(supplier, "door-" + System.nanoTime(), IoPriority.REGULAR);
}
}
Loading