use of org.dcache.tests.cells.CellStubHelper in project dcache by dCache.
the class RepositorySubsystemTest method createEntry4.
/* Helper method for creating a fourth entry in the repository.
*/
private void createEntry4(final boolean failSetAttributes, final boolean cancel, final ReplicaState transferState, final ReplicaState finalState) throws Throwable {
new CellStubHelper(cell) {
boolean setAttr;
boolean addCache;
@Message(required = false, step = 1, cell = "pnfs")
public Object whenFileIsGarbageCollected(PnfsClearCacheLocationMessage msg) {
msg.setSucceeded();
return msg;
}
@Message(required = false, step = 3, cell = "pnfs")
public Object whenDescriptorIsCommitted(PnfsSetFileAttributes msg) {
assertEquals(size4, msg.getFileAttributes().getSize());
if (failSetAttributes) {
msg.setFailed(1, null);
} else {
msg.setSucceeded();
}
setAttr = true;
return msg;
}
@Message(required = false, step = 5, cell = "pnfs")
public Object whenDescriptorFails(PnfsAddCacheLocationMessage msg) {
assertTrue(failSetAttributes || cancel);
msg.setSucceeded();
addCache = true;
return msg;
}
@Message(required = false, step = 5, cell = "pnfs")
public Object whenDescriptorFails(PnfsSetFileAttributes msg) {
assertTrue(failSetAttributes || cancel);
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws FileInCacheException, CacheException, InterruptedException, IOException {
List<StickyRecord> stickyRecords = Collections.emptyList();
ReplicaDescriptor handle = repository.createEntry(attributes4, transferState, finalState, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
try {
assertStep("No clear after this point", 2);
createFile(handle, size4);
if (!cancel) {
handle.commit();
}
} finally {
assertStep("Only failure registration after this point", 4);
handle.close();
}
assertEquals("SetFileAttributes must be sent unless we don't try to commit", !cancel, setAttr);
assertEquals("AddCacheLocation must be sent if not committed", cancel || failSetAttributes, addCache);
}
};
}
use of org.dcache.tests.cells.CellStubHelper in project dcache by dCache.
the class RepositorySubsystemTest method testRemoveOpenAgain.
@Test(expected = LockedCacheException.class)
public void testRemoveOpenAgain() throws Throwable {
repository.init();
repository.load();
stateChangeEvents.clear();
new CellStubHelper(cell) {
@Message(required = true, step = 1, cell = "pnfs")
public Object message(PnfsClearCacheLocationMessage msg) {
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws CacheException, InterruptedException, IllegalTransitionException {
ReplicaDescriptor h1 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
repository.setState(id1, REMOVED, "test");
expectStateChangeEvent(id1, PRECIOUS, REMOVED);
assertStep("Cache location should have been cleared", 1);
ReplicaDescriptor h2 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
}
};
}
use of org.dcache.tests.cells.CellStubHelper in project dcache by dCache.
the class RepositorySubsystemTest method testCreateEntryFromStore.
@Test
public void testCreateEntryFromStore() throws Throwable {
repository.init();
repository.load();
stateChangeEvents.clear();
new CellStubHelper(cell) {
@Message(required = true, step = 1, cell = "pnfs")
public Object message(PnfsSetFileAttributes msg) {
if (msg.getFileAttributes().isDefined(FileAttribute.SIZE)) {
return new CacheException("");
}
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws CacheException, InterruptedException {
List<StickyRecord> stickyRecords = Collections.emptyList();
ReplicaDescriptor handle = repository.createEntry(attributes5, FROM_STORE, CACHED, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
try {
createFile(handle, attributes5.getSize());
handle.commit();
} catch (IOException e) {
throw new DiskErrorCacheException(e.getMessage());
} finally {
handle.close();
}
}
};
}
use of org.dcache.tests.cells.CellStubHelper in project dcache by dCache.
the class RepositorySubsystemTest method createEntry.
private void createEntry(final FileAttributes attributes, final ReplicaState state, final List<StickyRecord> sticky) throws Throwable {
new CellStubHelper(cell) {
@Message(cell = "pnfs")
public Object message(PnfsSetFileAttributes msg) {
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws CacheException, IOException, InterruptedException {
ReplicaDescriptor handle = repository.createEntry(attributes, ReplicaState.FROM_CLIENT, state, sticky, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
try {
createFile(handle, attributes.getSize());
handle.commit();
} finally {
handle.close();
}
}
};
}
use of org.dcache.tests.cells.CellStubHelper in project dcache by dCache.
the class RepositorySubsystemTest method testRemoveWhileReading.
@Test
public void testRemoveWhileReading() throws Throwable {
repository.init();
repository.load();
stateChangeEvents.clear();
new CellStubHelper(cell) {
@Message(required = true, step = 0, cell = "pnfs")
public Object message(PnfsClearCacheLocationMessage msg) {
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws CacheException, InterruptedException, IllegalTransitionException {
ReplicaDescriptor handle1 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
repository.setState(id1, REMOVED, "test");
expectStateChangeEvent(id1, PRECIOUS, REMOVED);
assertNoStateChangeEvent();
assertStep("Cache location cleared", 1);
handle1.close();
expectStateChangeEvent(id1, REMOVED, DESTROYED);
}
};
}
Aggregations