use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class ScalarFnReflectorTest method testGetApplyMethod.
@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethod() throws InvocationTargetException, IllegalAccessException {
IncrementFn incrementFn = new IncrementFn();
Method method = ScalarFnReflector.getApplyMethod(incrementFn);
@Nullable Object result = method.invoke(incrementFn, Long.valueOf(24L));
assertEquals(Long.valueOf(25L), result);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class ScalarFnReflectorTest method testGetApplyMethodOverride.
@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethodOverride() throws InvocationTargetException, IllegalAccessException {
IncrementFnChild incrementFn = new IncrementFnChild();
Method method = ScalarFnReflector.getApplyMethod(incrementFn);
@Nullable Object result = method.invoke(incrementFn, Long.valueOf(24L));
assertEquals(Long.valueOf(26L), result);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class ScalarFnReflectorTest method testGetApplyMethodStatic.
@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethodStatic() throws InvocationTargetException, IllegalAccessException {
Method method = ScalarFnReflector.getApplyMethod(new IncrementFnWithStaticMethod());
@Nullable Object result = method.invoke(null, Long.valueOf(24L));
assertEquals(Long.valueOf(25L), result);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class PubsubGrpcClient method pull.
@Override
public List<IncomingMessage> pull(long requestTimeMsSinceEpoch, SubscriptionPath subscription, int batchSize, boolean returnImmediately) throws IOException {
PullRequest request = PullRequest.newBuilder().setSubscription(subscription.getPath()).setReturnImmediately(returnImmediately).setMaxMessages(batchSize).build();
PullResponse response = subscriberStub().pull(request);
if (response.getReceivedMessagesCount() == 0) {
return ImmutableList.of();
}
List<IncomingMessage> incomingMessages = new ArrayList<>(response.getReceivedMessagesCount());
for (ReceivedMessage message : response.getReceivedMessagesList()) {
PubsubMessage pubsubMessage = message.getMessage();
@Nullable Map<String, String> attributes = pubsubMessage.getAttributes();
// Timestamp.
long timestampMsSinceEpoch;
if (Strings.isNullOrEmpty(timestampAttribute)) {
Timestamp timestampProto = pubsubMessage.getPublishTime();
checkArgument(timestampProto != null, "Pubsub message is missing timestamp proto");
timestampMsSinceEpoch = timestampProto.getSeconds() * 1000 + timestampProto.getNanos() / 1000L / 1000L;
} else {
timestampMsSinceEpoch = extractTimestampAttribute(timestampAttribute, attributes);
}
// Ack id.
String ackId = message.getAckId();
checkState(!Strings.isNullOrEmpty(ackId));
// Record id, if any.
@Nullable String recordId = null;
if (idAttribute != null && attributes != null) {
recordId = attributes.get(idAttribute);
}
if (Strings.isNullOrEmpty(recordId)) {
// Fall back to the Pubsub provided message id.
recordId = pubsubMessage.getMessageId();
}
incomingMessages.add(IncomingMessage.of(pubsubMessage, timestampMsSinceEpoch, requestTimeMsSinceEpoch, ackId, recordId));
}
return incomingMessages;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class FieldValueTypeInformation method getNameOverride.
public static <T extends AnnotatedElement & Member> String getNameOverride(String original, T member) {
@Nullable SchemaFieldName fieldName = member.getAnnotation(SchemaFieldName.class);
@Nullable SchemaCaseFormat caseFormatAnnotation = member.getAnnotation(SchemaCaseFormat.class);
@Nullable SchemaCaseFormat classCaseFormatAnnotation = member.getDeclaringClass().getAnnotation(SchemaCaseFormat.class);
if (fieldName != null) {
if (caseFormatAnnotation != null) {
throw new RuntimeException(String.format("Cannot define both @SchemaFieldName and @SchemaCaseFormat. From member '%s'.", member.getName()));
}
return fieldName.value();
} else if (caseFormatAnnotation != null) {
return CaseFormat.LOWER_CAMEL.to(caseFormatAnnotation.value(), original);
} else if (classCaseFormatAnnotation != null) {
return CaseFormat.LOWER_CAMEL.to(classCaseFormatAnnotation.value(), original);
} else {
return original;
}
}
Aggregations