Search in sources :

Example 21 with SafeIllegalArgumentException

use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.

the class RefreshableWithInitialValueTest method preservesValidInitialValueIfFollowingValueIsNotValid.

@Test
public void preservesValidInitialValueIfFollowingValueIsNotValid() {
    SettableRefreshable<Integer> underlyingRefreshable = Refreshable.create(1);
    String expectedValue = "hello";
    when(function.apply(1)).thenReturn(expectedValue);
    when(function.apply(2)).thenThrow(new SafeIllegalArgumentException());
    Refreshable<String> refreshable = RefreshableWithInitialValue.of(underlyingRefreshable, function, "bye");
    verify(function).apply(1);
    String initial = refreshable.get();
    underlyingRefreshable.update(2);
    String updated = refreshable.get();
    assertThat(initial).describedAs("First returned value should be valid").isEqualTo(expectedValue);
    assertThat(updated).describedAs("Second returned value should be ignored").isEqualTo(expectedValue);
}
Also used : SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Test(org.junit.Test)

Example 22 with SafeIllegalArgumentException

use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.

the class PaxosStateLogMigrator method validateConsistency.

private static <V extends Persistable & Versionable> void validateConsistency(MigrationContext<V> context) {
    long migrationCutoff = calculateCutoff(context);
    long persistedCutoff = context.migrationState().getCutoff();
    long greatestSourceEntry = context.sourceLog().getGreatestLogEntry();
    Preconditions.checkState(migrationCutoff <= persistedCutoff || context.migrateFrom().isPresent(), "The migration to the destination state log was already performed in the past, but the " + "persisted cutoff value does not match a newly calculated one. This indicates the source " + "log has advanced since the migration was performed which could lead to data corruption if " + "allowed to continue.", SafeArg.of("fresh cutoff", migrationCutoff), SafeArg.of("persisted cutoff", persistedCutoff), SafeArg.of("source greatest entry", greatestSourceEntry), SafeArg.of("namespaceAndUseCase", context.namespaceAndUseCase()));
    if (greatestSourceEntry == PaxosAcceptor.NO_LOG_ENTRY) {
        return;
    }
    try {
        V source = context.hydrator().hydrateFromBytes(context.sourceLog().readRound(greatestSourceEntry));
        byte[] destinationBytes = context.destinationLog().readRound(greatestSourceEntry);
        V dest = destinationBytes != null ? context.hydrator().hydrateFromBytes(destinationBytes) : null;
        Preconditions.checkState(source.equalsIgnoringVersion(dest), "The migration to the destination state log was already performed in the past, but the " + "entry with the greatest sequence in source log does not match the entry in the " + "destination log. This indicates the source log has advanced since the migration was " + "performed which could lead to data corruption if allowed to continue.", SafeArg.of("source entry", source), SafeArg.of("destination entry", dest), SafeArg.of("namespaceAndUseCase", context.namespaceAndUseCase()));
    } catch (IOException e) {
        throw new SafeIllegalArgumentException("Unable to verify consistency between source and destination paxos " + "logs because the source log entry could not be read.");
    }
}
Also used : IOException(java.io.IOException) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 23 with SafeIllegalArgumentException

use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure by palantir.

the class ConjureParserUtils method parsePackageOrElseThrow.

public static String parsePackageOrElseThrow(Optional<ConjurePackage> conjurePackage, Optional<String> defaultPackage) {
    String packageName = conjurePackage.map(ConjurePackage::name).orElseGet(() -> defaultPackage.orElseThrow(() -> new SafeIllegalArgumentException(// TODO(rfink): Better errors: Can we provide context on where exactly no package was provided?
    "Must provide default conjure package or " + "explicit conjure package for every object and service")));
    PackageValidator.validate(packageName);
    return packageName;
}
Also used : PathString(com.palantir.conjure.parser.services.PathString) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Example 24 with SafeIllegalArgumentException

use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure by palantir.

the class ConjureParserTest method testConjureFieldDeprecation.

@Test
public void testConjureFieldDeprecation() {
    ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
    ObjectTypeDefinition object = conjure.types().definitions().objects().get(TypeName.of("BeanWithDeprecatedField")).visit(new TypeDefinitionVisitor<ObjectTypeDefinition>() {

        @Override
        public ObjectTypeDefinition visit(AliasTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }

        @Override
        public ObjectTypeDefinition visit(EnumTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }

        @Override
        public ObjectTypeDefinition visit(ObjectTypeDefinition def) {
            return def;
        }

        @Override
        public ObjectTypeDefinition visit(UnionTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition");
        }
    });
    assertThat(object.fields().get(FieldName.of("old")).deprecated()).hasValue("Test deprecated.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

Example 25 with SafeIllegalArgumentException

use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure by palantir.

the class ConjureParserTest method testConjureUnionTypeDeprecation.

@Test
public void testConjureUnionTypeDeprecation() {
    ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml"));
    UnionTypeDefinition union = conjure.types().definitions().objects().get(TypeName.of("UnionWithDeprecatedTypes")).visit(new TypeDefinitionVisitor<UnionTypeDefinition>() {

        @Override
        public UnionTypeDefinition visit(AliasTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(EnumTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(ObjectTypeDefinition _def) {
            throw new SafeIllegalArgumentException("Expected EnumTypeDefinition");
        }

        @Override
        public UnionTypeDefinition visit(UnionTypeDefinition def) {
            return def;
        }
    });
    assertThat(union.union().get(FieldName.of("first")).deprecated()).isNotPresent();
    assertThat(union.union().get(FieldName.of("second")).deprecated()).hasValue("Use 'first'.");
}
Also used : ObjectTypeDefinition(com.palantir.conjure.parser.types.complex.ObjectTypeDefinition) EnumTypeDefinition(com.palantir.conjure.parser.types.complex.EnumTypeDefinition) UnionTypeDefinition(com.palantir.conjure.parser.types.complex.UnionTypeDefinition) File(java.io.File) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) AliasTypeDefinition(com.palantir.conjure.parser.types.reference.AliasTypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)30 Test (org.junit.jupiter.api.Test)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Range (com.google.common.collect.Range)3 SafeArg (com.palantir.logsafe.SafeArg)3 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 Optional (java.util.Optional)3 Meter (com.codahale.metrics.Meter)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 TableMetadata (com.datastax.driver.core.TableMetadata)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ImmutableRangeSet.toImmutableRangeSet (com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet)2 MoreCollectors (com.google.common.collect.MoreCollectors)2 Multimap (com.google.common.collect.Multimap)2 RangeSet (com.google.common.collect.RangeSet)2 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)2