Commit 34971402 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

driver: add basic 'cancel' implementation

parent 6223ebfd
Pipeline #13867 passed with stages
in 3 minutes and 48 seconds
......@@ -16,11 +16,13 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.time.Instant;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
......@@ -307,6 +309,16 @@ public class CtaNearlineStorage implements NearlineStorage {
*/
@Override
public void cancel(UUID uuid) {
// FIXME: we need to cancel the requests in CTA.
var requestIterator = pendingRequests.entrySet().iterator();
while (requestIterator.hasNext()) {
var r = requestIterator.next().getValue().getRequest();
if (r.getId().equals(uuid)) {
r.failed(new CancellationException("Canceled by dCache"));
// no other matches expected.
break;
}
}
}
/**
......
......@@ -416,6 +416,24 @@ public class CtaNearlineStorageTest {
assertEquals("pending request count not zero", 0, driver.getPendingRequestsCount());
}
@Test
public void testCencelOfPendingRequest() {
var request = mockedStageRequest();
driver = new CtaNearlineStorage("foo", "bar");
driver.configure(drvConfig);
driver.start();
driver.stage(Set.of(request));
cta.waitToReply();
driver.cancel(request.getId());
assertEquals("unexpected pending request queue size", 0, driver.getPendingRequestsCount());
}
void waitToComplete() {
try {
waitForComplete.get(1, TimeUnit.SECONDS);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment