use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOMUpgradeFinalizer method testFinalizationWithUpgradeAction.
@Test
public void testFinalizationWithUpgradeAction() throws Exception {
Optional<OmUpgradeAction> action = Optional.of(om -> om.getVersion());
OzoneManager om = mockOzoneManager(0);
Iterable<OMLayoutFeature> lfs = mockFeatures("feature-1", "feature-2");
when(lfs.iterator().next().action(ON_FINALIZE)).thenReturn(action);
setupVersionManagerMockToFinalize(lfs);
OMUpgradeFinalizer finalizer = new OMUpgradeFinalizer(versionManager);
finalizer.finalize(CLIENT_ID, om);
Iterator<OMLayoutFeature> it = lfs.iterator();
OMLayoutFeature f = it.next();
// the first feature has an upgrade action, and the action execution is
// checked by verifying on om.getVersion
verify(om.getOmStorage(), once()).setLayoutVersion(f.layoutVersion());
verify(om, once()).getVersion();
// The second feature has a NOOP, but should update the layout version.
f = it.next();
verify(om.getOmStorage(), once()).setLayoutVersion(f.layoutVersion());
if (finalizer.isFinalizationDone()) {
when(versionManager.getUpgradeState()).thenReturn(FINALIZATION_DONE);
}
StatusAndMessages status = finalizer.reportStatus(CLIENT_ID, false);
assertEquals(FINALIZATION_DONE, status.status());
assertFalse(status.msgs().isEmpty());
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOMUpgradeFinalizer method mockOzoneManager.
private OzoneManager mockOzoneManager(int initialLayoutVersion) {
OzoneManager mock = mock(OzoneManager.class);
OMStorage st = mock(OMStorage.class);
storedLayoutVersion = initialLayoutVersion;
doAnswer((Answer<Void>) inv -> {
storedLayoutVersion = inv.getArgument(0, Integer.class);
return null;
}).when(st).setLayoutVersion(anyInt());
when(st.getLayoutVersion()).thenAnswer((Answer<Integer>) ignore -> storedLayoutVersion);
when(mock.getOmStorage()).thenReturn(st);
return mock;
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOMVersionManager method testOMLayoutFeaturesHaveIncreasingLayoutVersion.
@Test
public void testOMLayoutFeaturesHaveIncreasingLayoutVersion() throws Exception {
OMLayoutFeature[] values = OMLayoutFeature.values();
int currVersion = Integer.MIN_VALUE;
OMLayoutFeature lastFeature = null;
for (OMLayoutFeature lf : values) {
assertTrue(currVersion < lf.layoutVersion());
currVersion = lf.layoutVersion();
lastFeature = lf;
}
for (UpgradeActionType type : UpgradeActionType.values()) {
lastFeature.addAction(type, arg -> {
String v = arg.getVersion();
});
}
OzoneManager omMock = mock(OzoneManager.class);
for (UpgradeActionType type : UpgradeActionType.values()) {
lastFeature.action(type).get().execute(omMock);
}
verify(omMock, times(UpgradeActionType.values().length)).getVersion();
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOMLayoutFeatureAspect method testPreExecuteLayoutCheck.
@Test
public void testPreExecuteLayoutCheck() throws Exception {
OzoneManager om = mock(OzoneManager.class);
OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
when(lvm.isAllowed(anyString())).thenReturn(false);
when(lvm.getFeature(anyString())).thenReturn(INITIAL_VERSION);
when(om.getVersionManager()).thenReturn(lvm);
MockOmRequest mockOmRequest = new MockOmRequest();
OMLayoutFeatureAspect aspect = new OMLayoutFeatureAspect();
JoinPoint joinPoint = mock(JoinPoint.class);
when(joinPoint.getArgs()).thenReturn(new Object[] { om });
when(joinPoint.getTarget()).thenReturn(mockOmRequest);
LambdaTestUtils.intercept(OMException.class, "cannot be invoked before finalization", () -> aspect.beforeRequestApplyTxn(joinPoint));
}
Aggregations