Skip to content

Commit

Permalink
HDDS-11963. Address review comments
Browse files Browse the repository at this point in the history
Change-Id: I11bff280f429d2eb64f8828887f7349e169e938f
  • Loading branch information
swamirishi committed Dec 19, 2024
1 parent b819b63 commit bfa7618
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package org.apache.hadoop.hdds;

import org.apache.hadoop.ozone.Version;
import org.apache.hadoop.ozone.Versioned;

/**
* Base type for component version enums.
*/
public interface ComponentVersion extends Version {
public interface ComponentVersion extends Versioned {

/**
* Returns the description of the version enum value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
/**
* Base class defining the version in the entire system.
*/
public interface Version {
public interface Versioned {
int version();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

package org.apache.hadoop.ozone.upgrade;

import org.apache.hadoop.ozone.Version;
import org.apache.hadoop.ozone.Versioned;

import java.util.Optional;

/**
* Generic Layout feature interface for Ozone.
*/
public interface LayoutFeature extends Version {
public interface LayoutFeature extends Versioned {
String name();

int layoutVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.hadoop.ozone.om.request.validation;

import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.Version;
import org.apache.hadoop.ozone.Versioned;
import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
import org.apache.hadoop.ozone.upgrade.LayoutVersionManager;
Expand All @@ -31,7 +31,7 @@ public enum VersionExtractor {
*/
LAYOUT_VERSION_EXTRACTOR {
@Override
public Version extractVersion(OMRequest req, ValidationContext ctx) {
public Versioned extractVersion(OMRequest req, ValidationContext ctx) {
LayoutVersionManager layoutVersionManager = ctx.versionManager();
return ctx.versionManager().getFeature(layoutVersionManager.getMetadataLayoutVersion());
}
Expand All @@ -47,7 +47,7 @@ public Class<OMLayoutFeature> getVersionClass() {
*/
CLIENT_VERSION_EXTRACTOR {
@Override
public Version extractVersion(OMRequest req, ValidationContext ctx) {
public Versioned extractVersion(OMRequest req, ValidationContext ctx) {
return req.getVersion() > ClientVersion.CURRENT_VERSION ?
ClientVersion.FUTURE_VERSION : ClientVersion.fromProtoValue(req.getVersion());
}
Expand All @@ -58,6 +58,6 @@ public Class<ClientVersion> getVersionClass() {
}
};

public abstract Version extractVersion(OMRequest req, ValidationContext ctx);
public abstract Class<? extends Version> getVersionClass();
public abstract Versioned extractVersion(OMRequest req, ValidationContext ctx);
public abstract Class<? extends Versioned> getVersionClass();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
package org.apache.hadoop.ozone.om.request.validation;

import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.Version;
import org.apache.hadoop.ozone.Versioned;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature;
import org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
import org.apache.hadoop.ozone.upgrade.LayoutVersionManager;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;

Expand All @@ -38,37 +37,38 @@

class TestVersionExtractor {

private static Stream<Arguments> layoutValues() {
return Arrays.stream(OMLayoutFeature.values()).map(Arguments::of);
}

private static Stream<Arguments> clientVersionValues() {
return Stream.of(
Arrays.stream(ClientVersion.values())
.map(clientVersion -> Arguments.of(clientVersion, clientVersion.version())),
IntStream.range(1, 10)
.mapToObj(delta -> Arguments.of(ClientVersion.FUTURE_VERSION, ClientVersion.CURRENT_VERSION + delta))
).flatMap(Function.identity());
private static Stream<Arguments> futureClientVersionValues() {
return IntStream.range(1, 10).mapToObj(delta -> Arguments.of(ClientVersion.CURRENT_VERSION + delta));
}

@ParameterizedTest
@MethodSource("layoutValues")
@EnumSource(OMLayoutFeature.class)
void testLayoutVersionExtractor(OMLayoutFeature layoutVersionValue) throws OMException {
ValidationContext context = mock(ValidationContext.class);
LayoutVersionManager layoutVersionManager = new OMLayoutVersionManager(layoutVersionValue.version());
when(context.versionManager()).thenReturn(layoutVersionManager);
Version version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context);
Versioned version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context);
assertEquals(layoutVersionValue, version);
assertEquals(OMLayoutFeature.class, VersionExtractor.LAYOUT_VERSION_EXTRACTOR.getVersionClass());
}

@ParameterizedTest
@MethodSource("clientVersionValues")
void testClientVersionExtractor(ClientVersion expectedClientVersion, int clientVersion) {
@EnumSource(ClientVersion.class)
void testClientVersionExtractor(ClientVersion expectedClientVersion) {
OMRequest request = mock(OMRequest.class);
when(request.getVersion()).thenReturn(clientVersion);
Version version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null);
when(request.getVersion()).thenReturn(expectedClientVersion.version());
Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null);
assertEquals(expectedClientVersion, version);
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass());
}

@ParameterizedTest
@MethodSource("futureClientVersionValues")
void testClientVersionExtractorForFutureValues(int clientVersion) {
OMRequest request = mock(OMRequest.class);
when(request.getVersion()).thenReturn(clientVersion);
Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null);
assertEquals(ClientVersion.FUTURE_VERSION, version);
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass());
}
}

0 comments on commit bfa7618

Please sign in to comment.