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);
}
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.");
}
}
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;
}
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.");
}
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'.");
}
Aggregations