use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class PortablePipelineJarCreator method createManifest.
@VisibleForTesting
Manifest createManifest(Class mainClass, String defaultJobName) {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
boolean classHasMainMethod = false;
try {
Class returnType = mainClass.getMethod("main", String[].class).getReturnType();
if (returnType == Void.TYPE) {
classHasMainMethod = true;
} else {
LOG.warn("No Main-Class will be set in jar because main method in {} returns {}, expected void", mainClass, returnType);
}
} catch (NoSuchMethodException e) {
LOG.warn("No Main-Class will be set in jar because {} lacks a main method.", mainClass);
}
if (classHasMainMethod) {
manifest.getMainAttributes().put(Name.MAIN_CLASS, mainClass.getName());
}
return manifest;
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class PortableRunner method create.
@VisibleForTesting
static PortableRunner create(PipelineOptions options, ManagedChannelFactory channelFactory) {
PortablePipelineOptions portableOptions = PipelineOptionsValidator.validate(PortablePipelineOptions.class, options);
String endpoint = portableOptions.getJobEndpoint();
return new PortableRunner(options, endpoint, channelFactory);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class RenameFields method renameSchema.
// Apply the user-specified renames to the input schema.
@VisibleForTesting
static void renameSchema(Schema inputSchema, Collection<RenamePair> renames, Map<UUID, Schema> renamedSchemasMap, Map<UUID, BitSet> nestedFieldRenamedMap) {
// The mapping of renames to apply at this level of the schema.
Map<Integer, String> topLevelRenames = Maps.newHashMap();
// For nested schemas, collect all applicable renames here.
Multimap<Integer, RenamePair> nestedRenames = ArrayListMultimap.create();
for (RenamePair rename : renames) {
FieldAccessDescriptor access = rename.getFieldAccessDescriptor();
if (!access.fieldIdsAccessed().isEmpty()) {
// This references a field at this level of the schema.
Integer fieldId = Iterables.getOnlyElement(access.fieldIdsAccessed());
topLevelRenames.put(fieldId, rename.getNewName());
} else {
// This references a nested field.
Map.Entry<Integer, FieldAccessDescriptor> nestedAccess = Iterables.getOnlyElement(access.nestedFieldsById().entrySet());
nestedFieldRenamedMap.computeIfAbsent(inputSchema.getUUID(), s -> new BitSet(inputSchema.getFieldCount())).set(nestedAccess.getKey());
nestedRenames.put(nestedAccess.getKey(), RenamePair.of(nestedAccess.getValue(), rename.getNewName()));
}
}
Schema.Builder builder = Schema.builder();
for (int i = 0; i < inputSchema.getFieldCount(); ++i) {
Field field = inputSchema.getField(i);
FieldType fieldType = field.getType();
String newName = topLevelRenames.getOrDefault(i, field.getName());
Collection<RenamePair> nestedFieldRenames = nestedRenames.asMap().getOrDefault(i, Collections.emptyList());
builder.addField(newName, renameFieldType(fieldType, nestedFieldRenames, renamedSchemasMap, nestedFieldRenamedMap));
}
renamedSchemasMap.put(inputSchema.getUUID(), builder.build());
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class CoderProperties method decode.
@VisibleForTesting
static <T> T decode(Coder<T> coder, Coder.Context context, byte[] bytes) throws CoderException, IOException {
@SuppressWarnings("unchecked") Coder<T> deserializedCoder = SerializableUtils.clone(coder);
byte[] buffer;
if (Objects.equals(context, Coder.Context.NESTED)) {
buffer = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, buffer, 0, bytes.length);
buffer[bytes.length] = 1;
} else {
buffer = bytes;
}
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(buffer));
T value = deserializedCoder.decode(new UnownedInputStream(cis), context);
assertThat("consumed bytes equal to encoded bytes", cis.getCount(), equalTo((long) bytes.length));
return value;
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class DoFnSignatures method analyzeOnTimerMethod.
@VisibleForTesting
static DoFnSignature.OnTimerMethod analyzeOnTimerMethod(ErrorReporter errors, TypeDescriptor<? extends DoFn<?, ?>> fnClass, Method m, String timerId, TypeDescriptor<?> inputT, TypeDescriptor<?> outputT, FnAnalysisContext fnContext) {
errors.checkArgument(void.class.equals(m.getReturnType()), "Must return void");
Type[] params = m.getGenericParameterTypes();
MethodAnalysisContext methodContext = MethodAnalysisContext.create();
boolean requiresStableInput = m.isAnnotationPresent(DoFn.RequiresStableInput.class);
@Nullable TypeDescriptor<? extends BoundedWindow> windowT = getWindowType(fnClass, m);
List<Parameter> extraParameters = new ArrayList<>();
ErrorReporter onTimerErrors = errors.forMethod(DoFn.OnTimer.class, m);
for (int i = 0; i < params.length; ++i) {
Parameter parameter = analyzeExtraParameter(onTimerErrors, fnContext, methodContext, ParameterDescription.of(m, i, fnClass.resolveType(params[i]), Arrays.asList(m.getParameterAnnotations()[i])), inputT, outputT);
checkParameterOneOf(errors, parameter, ALLOWED_ON_TIMER_PARAMETERS);
extraParameters.add(parameter);
}
return DoFnSignature.OnTimerMethod.create(m, timerId, requiresStableInput, windowT, extraParameters);
}
Aggregations