Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-2867 Fixed protocol substitutions #1495

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,22 +34,22 @@ final class Lz4Substitution {
public Lz4Substitution(DriverContext context) {}

@Substitute
protected ByteBuf compressHeap(ByteBuf input) {
protected ByteBuf compressHeap(ByteBuf input, boolean prependWithUncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf decompressDirect(ByteBuf input) {
protected ByteBuf decompressDirect(ByteBuf input, int uncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf decompressHeap(ByteBuf input) {
protected ByteBuf decompressHeap(ByteBuf input, int uncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf compressDirect(ByteBuf input) {
protected ByteBuf compressDirect(ByteBuf input, boolean prependWithUncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}
}
Expand Up @@ -31,22 +31,22 @@ final class SnappySubstitution {
private final String EXCEPTION_MSG = "Snappy compression is not supported for native images";

@Substitute
protected ByteBuf compressHeap(ByteBuf input) {
protected ByteBuf compressHeap(ByteBuf input, boolean prependWithUncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf decompressDirect(ByteBuf input) {
protected ByteBuf decompressDirect(ByteBuf input, int uncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf decompressHeap(ByteBuf input) {
protected ByteBuf decompressHeap(ByteBuf input, int uncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}

@Substitute
protected ByteBuf compressDirect(ByteBuf input) {
protected ByteBuf compressDirect(ByteBuf input, boolean prependWithUncompressedLength) {
throw new UnsupportedOperationException(EXCEPTION_MSG);
}
}
@@ -0,0 +1,70 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datastax.oss.driver.internal.core.protocol;

import static org.assertj.core.api.Assertions.assertThat;

import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class CompressSubstitutionsTest {
adutra marked this conversation as resolved.
Show resolved Hide resolved

private static final Set<String> EXCLUDED_METHOD_NAMES =
ImmutableSet.of("algorithm", "readUncompressedLength");

private static final Comparator<Method> METHOD_SIGNATURE_COMPARATOR =
Comparator.comparing(Method::getName)
.thenComparing(Method::getReturnType, (ret1, ret2) -> ret1.equals(ret2) ? 0 : -1)
.thenComparing(
Method::getParameterTypes,
(params1, params2) -> Arrays.deepEquals(params1, params2) ? 0 : -1);

@Test
@UseDataProvider(value = "substitutionClasses")
public void should_substitute_compressor_methods(
Class<?> substitutedClass, Class<?> substitutionClass) {

Set<Method> methodsToSubstitute =
Arrays.stream(substitutedClass.getDeclaredMethods())
.filter(method -> !EXCLUDED_METHOD_NAMES.contains(method.getName()))
.collect(Collectors.toSet());

Set<Method> substitutedMethods =
Arrays.stream(substitutionClass.getDeclaredMethods()).collect(Collectors.toSet());

assertThat(methodsToSubstitute)
.usingElementComparator(METHOD_SIGNATURE_COMPARATOR)
.containsExactlyInAnyOrderElementsOf(substitutedMethods);
}

@DataProvider
public static Object[][] substitutionClasses() {
return new Object[][] {
{Lz4Compressor.class, Lz4Substitution.class},
{SnappyCompressor.class, SnappySubstitution.class}
};
}
}