Search in sources :

Example 1 with ListHandler

use of org.dcache.namespace.ListHandler in project dcache by dCache.

the class MonitoringNameSpaceProviderTest method shouldNotifyOnListWithSingleEntry.

@Test
public void shouldNotifyOnListWithSingleEntry() throws Exception {
    ListHandler handler = mock(ListHandler.class);
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    given(inner.pathToPnfsid(any(), eq("/foo"), anyBoolean())).willReturn(target);
    willAnswer(i -> {
        ListHandler h = i.getArgument(5, ListHandler.class);
        h.addEntry("bar", new FileAttributes());
        return null;
    }).given(inner).list(any(), eq("/foo"), any(), any(), any(), any());
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "foo"));
    monitor.list(TEST_USER, "/foo", null, Range.all(), EnumSet.noneOf(FileAttribute.class), handler);
    verify(inner).list(eq(TEST_USER), eq("/foo"), eq(null), eq(Range.all()), any(), any());
    verify(handler).addEntry(eq("bar"), any());
    InOrder childEvents = inOrder(receiver);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_OPEN, parent, "foo", FileType.DIR);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_CLOSE_NOWRITE, parent, "foo", FileType.DIR);
    InOrder dirEvents = inOrder(receiver);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_OPEN, target, FileType.DIR);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_CLOSE_NOWRITE, target, FileType.DIR);
    verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
Also used : ListHandler(org.dcache.namespace.ListHandler) InOrder(org.mockito.InOrder) PnfsId(diskCacheV111.util.PnfsId) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 2 with ListHandler

use of org.dcache.namespace.ListHandler in project dcache by dCache.

the class MonitoringNameSpaceProviderTest method shouldNotNotifyOnUnsuccessfulList.

@Test
public void shouldNotNotifyOnUnsuccessfulList() throws Exception {
    ListHandler handler = mock(ListHandler.class);
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    given(inner.pathToPnfsid(any(), eq("/foo"), anyBoolean())).willReturn(target);
    willThrow(CacheException.class).given(inner).list(any(), eq("/foo"), any(), any(), any(), any());
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "foo"));
    try {
        monitor.list(TEST_USER, "/foo", null, Range.all(), EnumSet.noneOf(FileAttribute.class), handler);
        fail("list unexpectedly succeeded");
    } catch (CacheException e) {
    }
    verify(receiver, never()).notifyChildEvent(any(), any(), any(), any());
    verify(receiver, never()).notifySelfEvent(any(), any(), any());
    verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
Also used : ListHandler(org.dcache.namespace.ListHandler) CacheException(diskCacheV111.util.CacheException) PnfsId(diskCacheV111.util.PnfsId) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 3 with ListHandler

use of org.dcache.namespace.ListHandler in project dcache by dCache.

the class MonitoringNameSpaceProviderTest method shouldNotifyOnListWithNoEntries.

@Test
public void shouldNotifyOnListWithNoEntries() throws Exception {
    ListHandler handler = mock(ListHandler.class);
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    given(inner.pathToPnfsid(any(), eq("/foo"), anyBoolean())).willReturn(target);
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "foo"));
    monitor.list(TEST_USER, "/foo", null, Range.all(), EnumSet.noneOf(FileAttribute.class), handler);
    verify(inner).list(eq(TEST_USER), eq("/foo"), eq(null), eq(Range.all()), any(), any());
    verify(handler, never()).addEntry(any(), any());
    InOrder childEvents = inOrder(receiver);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_OPEN, parent, "foo", FileType.DIR);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_CLOSE_NOWRITE, parent, "foo", FileType.DIR);
    InOrder dirEvents = inOrder(receiver);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_OPEN, target, FileType.DIR);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_CLOSE_NOWRITE, target, FileType.DIR);
    verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
Also used : ListHandler(org.dcache.namespace.ListHandler) InOrder(org.mockito.InOrder) PnfsId(diskCacheV111.util.PnfsId) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 4 with ListHandler

use of org.dcache.namespace.ListHandler in project dcache by dCache.

the class MonitoringNameSpaceProviderTest method shouldNotifyOnListWithTwoEntries.

@Test
public void shouldNotifyOnListWithTwoEntries() throws Exception {
    ListHandler handler = mock(ListHandler.class);
    PnfsId parent = new PnfsId("000000000000000000000000000000000001");
    PnfsId target = new PnfsId("000000000000000000000000000000000002");
    given(inner.pathToPnfsid(any(), eq("/foo"), anyBoolean())).willReturn(target);
    willAnswer(i -> {
        ListHandler h = i.getArgument(5, ListHandler.class);
        h.addEntry("bar-1", new FileAttributes());
        h.addEntry("bar-2", new FileAttributes());
        return null;
    }).given(inner).list(any(), eq("/foo"), any(), any(), any(), any());
    given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "foo"));
    monitor.list(TEST_USER, "/foo", null, Range.all(), EnumSet.noneOf(FileAttribute.class), handler);
    verify(inner).list(eq(TEST_USER), eq("/foo"), eq(null), eq(Range.all()), any(), any());
    verify(handler).addEntry(eq("bar-1"), any());
    verify(handler).addEntry(eq("bar-2"), any());
    InOrder childEvents = inOrder(receiver);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_OPEN, parent, "foo", FileType.DIR);
    childEvents.verify(receiver).notifyChildEvent(EventType.IN_CLOSE_NOWRITE, parent, "foo", FileType.DIR);
    InOrder dirEvents = inOrder(receiver);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_OPEN, target, FileType.DIR);
    dirEvents.verify(receiver).notifySelfEvent(EventType.IN_CLOSE_NOWRITE, target, FileType.DIR);
    verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
Also used : ListHandler(org.dcache.namespace.ListHandler) InOrder(org.mockito.InOrder) PnfsId(diskCacheV111.util.PnfsId) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Aggregations

PnfsId (diskCacheV111.util.PnfsId)4 FileAttribute (org.dcache.namespace.FileAttribute)4 ListHandler (org.dcache.namespace.ListHandler)4 Test (org.junit.Test)4 InOrder (org.mockito.InOrder)3 FileAttributes (org.dcache.vehicles.FileAttributes)2 CacheException (diskCacheV111.util.CacheException)1