use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.
the class AccessTimeUpdaterTest method updateAccessTimeImmediately.
@Test
public void updateAccessTimeImmediately() throws Exception {
mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 0, 0, 0);
mAccessTimeUpdater.start();
String path = "/foo";
JournalContext journalContext = mock(JournalContext.class);
when(journalContext.get()).thenReturn(journalContext);
createInode(path, CreateFileContext.defaults());
long accessTime = CommonUtils.getCurrentMs() + 100L;
long inodeId;
try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), accessTime);
inodeId = lockedInodes.getInode().getId();
}
// verify journal entry is logged
ArgumentCaptor<Journal.JournalEntry> captor = ArgumentCaptor.forClass(Journal.JournalEntry.class);
verify(journalContext).append(captor.capture());
assertTrue(captor.getValue().hasUpdateInode());
assertEquals(inodeId, captor.getValue().getUpdateInode().getId());
assertEquals(accessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
// verify inode attribute is updated
assertEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
}
use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.
the class AccessTimeUpdaterTest method updateAccessTimeAsyncOnShutdown.
@Test
public void updateAccessTimeAsyncOnShutdown() throws Exception {
mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 10 * Constants.SECOND_MS, 0, 0);
mAccessTimeUpdater.start(mScheduler);
String path = "/foo";
createInode(path, CreateFileContext.defaults());
JournalContext journalContext = mock(JournalContext.class);
when(journalContext.get()).thenReturn(journalContext);
when(mFileSystemMaster.createJournalContext()).thenReturn(journalContext);
long accessTime = CommonUtils.getCurrentMs() + 100L;
long inodeId;
try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), accessTime);
inodeId = lockedInodes.getInode().getId();
}
// verify inode attribute is updated
assertEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
mScheduler.jumpAndExecute(1, TimeUnit.SECONDS);
// verify journal entry is NOT logged yet
verify(journalContext, never()).append(any(Journal.JournalEntry.class));
// wait for the flush to complete
mContext.getJournalSystem().stop();
// / verify journal entry is logged after the flush interval
ArgumentCaptor<Journal.JournalEntry> captor = ArgumentCaptor.forClass(Journal.JournalEntry.class);
verify(journalContext).append(captor.capture());
assertTrue(captor.getValue().hasUpdateInode());
assertEquals(inodeId, captor.getValue().getUpdateInode().getId());
assertEquals(accessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
}
use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.
the class AccessTimeUpdaterTest method updateAccessTimePrecisionAsync.
@Test
public void updateAccessTimePrecisionAsync() throws Exception {
mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), Constants.MINUTE_MS, Constants.HOUR_MS, 0);
mAccessTimeUpdater.start(mScheduler);
String path = "/foo";
createInode(path, CreateFileContext.defaults());
JournalContext journalContext = mock(JournalContext.class);
when(journalContext.get()).thenReturn(journalContext);
when(mFileSystemMaster.createJournalContext()).thenReturn(journalContext);
long accessTime = CommonUtils.getCurrentMs() + 100L;
long inodeId;
try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), accessTime);
inodeId = lockedInodes.getInode().getId();
}
mScheduler.jumpAndExecute(2, TimeUnit.MINUTES);
// verify inode attribute is not updated
assertNotEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
// verify journal entry is not logged
verify(journalContext, never()).append(any(Journal.JournalEntry.class));
long newAccessTime = CommonUtils.getCurrentMs() + 2 * Constants.HOUR_MS;
// update access time with a much later timestamp
try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), newAccessTime);
inodeId = lockedInodes.getInode().getId();
}
// verify inode attribute is updated
assertEquals(newAccessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
mScheduler.jumpAndExecute(2, TimeUnit.SECONDS);
// verify journal entry is not logged
verify(journalContext, never()).append(any(Journal.JournalEntry.class));
mScheduler.jumpAndExecute(2, TimeUnit.MINUTES);
// / verify journal entry is logged after the flush interval
ArgumentCaptor<Journal.JournalEntry> captor = ArgumentCaptor.forClass(Journal.JournalEntry.class);
verify(journalContext).append(captor.capture());
assertTrue(captor.getValue().hasUpdateInode());
assertEquals(inodeId, captor.getValue().getUpdateInode().getId());
assertEquals(newAccessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
}
use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.
the class AccessTimeUpdaterTest method updateAccessTimeAsync.
@Test
public void updateAccessTimeAsync() throws Exception {
mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 10 * Constants.SECOND_MS, 0, 0);
mAccessTimeUpdater.start(mScheduler);
String path = "/foo";
createInode(path, CreateFileContext.defaults());
JournalContext journalContext = mock(JournalContext.class);
when(journalContext.get()).thenReturn(journalContext);
when(mFileSystemMaster.createJournalContext()).thenReturn(journalContext);
long accessTime = CommonUtils.getCurrentMs() + 100L;
long inodeId;
try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), accessTime);
inodeId = lockedInodes.getInode().getId();
}
// verify inode attribute is updated
assertEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
mScheduler.jumpAndExecute(1, TimeUnit.SECONDS);
// verify journal entry is NOT logged yet
verify(journalContext, never()).append(any(Journal.JournalEntry.class));
// wait for the flush to complete
mScheduler.jumpAndExecute(11, TimeUnit.SECONDS);
// / verify journal entry is logged after the flush interval
ArgumentCaptor<Journal.JournalEntry> captor = ArgumentCaptor.forClass(Journal.JournalEntry.class);
verify(journalContext).append(captor.capture());
assertTrue(captor.getValue().hasUpdateInode());
assertEquals(inodeId, captor.getValue().getUpdateInode().getId());
assertEquals(accessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
}
use of alluxio.master.journal.JournalContext 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"));
}
Aggregations