Search in sources :

Example 1 with OperationContext

use of alluxio.master.file.contexts.OperationContext in project alluxio by Alluxio.

the class UfsStatusCacheTest method testFetchCancel.

@Test
public void testFetchCancel() throws Exception {
    spyUfs();
    doAnswer((Answer<UfsStatus[]>) invocation -> {
        Thread.sleep(30 * Constants.HOUR_MS);
        return new UfsStatus[] { Mockito.mock(UfsStatus.class) };
    }).when(mUfs).listStatus(any(String.class));
    mCache.prefetchChildren(new AlluxioURI("/"), mMountTable);
    final BlockDeletionContext bdc = mock(BlockDeletionContext.class);
    final JournalContext jc = mock(JournalContext.class);
    final OperationContext oc = mock(OperationContext.class);
    when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList());
    final RpcContext rpcContext = new RpcContext(bdc, jc, oc);
    AtomicReference<RuntimeException> ref = new AtomicReference<>(null);
    Thread t = new Thread(() -> {
        try {
            mCache.fetchChildrenIfAbsent(rpcContext, new AlluxioURI("/"), mMountTable);
            fail("Should not have been able to fetch children");
        } catch (RuntimeException e) {
            ref.set(e);
        } catch (InterruptedException | InvalidPathException e) {
        // do nothing
        }
    });
    t.start();
    when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList(new CallTracker() {

        @Override
        public boolean isCancelled() {
            return true;
        }

        @Override
        public Type getType() {
            return Type.GRPC_CLIENT_TRACKER;
        }
    }));
    t.join();
    final RuntimeException runtimeException = ref.get();
    assertNotNull(runtimeException);
    MatcherAssert.assertThat(runtimeException.getMessage(), Matchers.stringContainsInOrder("Call cancelled"));
}
Also used : Mockito.doThrow(org.mockito.Mockito.doThrow) Future(java.util.concurrent.Future) InvalidPathException(alluxio.exception.InvalidPathException) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Assert.fail(org.junit.Assert.fail) LocalUnderFileSystem(alluxio.underfs.local.LocalUnderFileSystem) ServerConfiguration(alluxio.conf.ServerConfiguration) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) NoopUfsAbsentPathCache(alluxio.master.file.meta.NoopUfsAbsentPathCache) MatcherAssert(org.hamcrest.MatcherAssert) Assert.assertFalse(org.junit.Assert.assertFalse) RpcContext(alluxio.master.file.RpcContext) JournalContext(alluxio.master.journal.JournalContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OperationContext(alluxio.master.file.contexts.OperationContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) PathUtils(alluxio.util.io.PathUtils) Answer(org.mockito.stubbing.Answer) Lists(com.google.common.collect.Lists) Constants(alluxio.Constants) MountInfo(alluxio.master.file.meta.options.MountInfo) AlluxioURI(alluxio.AlluxioURI) MountPOptions(alluxio.grpc.MountPOptions) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ReentrantLock(java.util.concurrent.locks.ReentrantLock) IdUtils(alluxio.util.IdUtils) Assert.assertNotNull(org.junit.Assert.assertNotNull) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) UfsAbsentPathCache(alluxio.master.file.meta.UfsAbsentPathCache) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Lock(java.util.concurrent.locks.Lock) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) CallTracker(alluxio.master.file.contexts.CallTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MountTable(alluxio.master.file.meta.MountTable) TemporaryFolder(org.junit.rules.TemporaryFolder) OperationContext(alluxio.master.file.contexts.OperationContext) JournalContext(alluxio.master.journal.JournalContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvalidPathException(alluxio.exception.InvalidPathException) RpcContext(alluxio.master.file.RpcContext) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) AlluxioURI(alluxio.AlluxioURI) CallTracker(alluxio.master.file.contexts.CallTracker) Test(org.junit.Test)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1 Constants (alluxio.Constants)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 InvalidPathException (alluxio.exception.InvalidPathException)1 MountPOptions (alluxio.grpc.MountPOptions)1 BlockDeletionContext (alluxio.master.file.BlockDeletionContext)1 RpcContext (alluxio.master.file.RpcContext)1 CallTracker (alluxio.master.file.contexts.CallTracker)1 OperationContext (alluxio.master.file.contexts.OperationContext)1 MountTable (alluxio.master.file.meta.MountTable)1 NoopUfsAbsentPathCache (alluxio.master.file.meta.NoopUfsAbsentPathCache)1 UfsAbsentPathCache (alluxio.master.file.meta.UfsAbsentPathCache)1 MountInfo (alluxio.master.file.meta.options.MountInfo)1 JournalContext (alluxio.master.journal.JournalContext)1 LocalUnderFileSystem (alluxio.underfs.local.LocalUnderFileSystem)1 IdUtils (alluxio.util.IdUtils)1 PathUtils (alluxio.util.io.PathUtils)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1