Search in sources :

Example 26 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class JarFileChecker method checkJar.

@VisibleForTesting
static int checkJar(Path file) throws Exception {
    final URI uri = file.toUri();
    int numSevereIssues = 0;
    try (final FileSystem fileSystem = FileSystems.newFileSystem(new URI("jar:file", uri.getHost(), uri.getPath(), uri.getFragment()), Collections.emptyMap())) {
        if (isTestJarAndEmpty(file, fileSystem.getPath("/"))) {
            return 0;
        }
        if (!noticeFileExistsAndIsValid(fileSystem.getPath("META-INF", "NOTICE"), file)) {
            numSevereIssues++;
        }
        if (!licenseFileExistsAndIsValid(fileSystem.getPath("META-INF", "LICENSE"), file)) {
            numSevereIssues++;
        }
        numSevereIssues += getNumLicenseFilesOutsideMetaInfDirectory(file, fileSystem.getPath("/"));
        numSevereIssues += getFilesWithIncompatibleLicenses(file, fileSystem.getPath("/"));
    }
    return numSevereIssues;
}
Also used : FileSystem(java.nio.file.FileSystem) URI(java.net.URI) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 27 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class CollectSinkFunction method serializeAccumulatorResult.

@VisibleForTesting
public static byte[] serializeAccumulatorResult(long offset, String version, long lastCheckpointedOffset, List<byte[]> buffer) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputViewStreamWrapper wrapper = new DataOutputViewStreamWrapper(baos);
    wrapper.writeLong(offset);
    CollectCoordinationResponse finalResponse = new CollectCoordinationResponse(version, lastCheckpointedOffset, buffer);
    finalResponse.serialize(wrapper);
    return baos.toByteArray();
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 28 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class PseudoRandomValueSelector method getGitCommitId.

@VisibleForTesting
public static Optional<String> getGitCommitId() {
    try {
        Process process = new ProcessBuilder("git", "rev-parse", "HEAD").start();
        try (InputStream input = process.getInputStream()) {
            final String commit = IOUtils.toString(input, Charset.defaultCharset()).trim();
            if (commit.matches("[a-f0-9]{40}")) {
                return Optional.of(commit);
            }
            LOG.debug("Cannot parse {}", commit);
        }
    } catch (IOException e) {
        LOG.debug("Could not invoke git", e);
    }
    return Optional.empty();
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 29 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class SavepointV0Serializer method serializeOld.

@VisibleForTesting
public void serializeOld(SavepointV0 savepoint, DataOutputStream dos) throws IOException {
    dos.writeLong(savepoint.getCheckpointId());
    Collection<org.apache.flink.migration.runtime.checkpoint.TaskState> taskStates = savepoint.getOldTaskStates();
    dos.writeInt(taskStates.size());
    for (org.apache.flink.migration.runtime.checkpoint.TaskState taskState : savepoint.getOldTaskStates()) {
        // Vertex ID
        dos.writeLong(taskState.getJobVertexID().getLowerPart());
        dos.writeLong(taskState.getJobVertexID().getUpperPart());
        // Parallelism
        int parallelism = taskState.getParallelism();
        dos.writeInt(parallelism);
        // Sub task states
        dos.writeInt(taskState.getNumberCollectedStates());
        for (int i = 0; i < parallelism; i++) {
            SubtaskState subtaskState = taskState.getState(i);
            if (subtaskState != null) {
                dos.writeInt(i);
                SerializedValue<?> serializedValue = subtaskState.getState();
                if (serializedValue == null) {
                    // null
                    dos.writeInt(-1);
                } else {
                    byte[] serialized = serializedValue.getByteArray();
                    dos.writeInt(serialized.length);
                    dos.write(serialized, 0, serialized.length);
                }
                dos.writeLong(subtaskState.getStateSize());
                dos.writeLong(subtaskState.getDuration());
            }
        }
        // Key group states
        dos.writeInt(taskState.getNumberCollectedKvStates());
        for (int i = 0; i < parallelism; i++) {
            KeyGroupState keyGroupState = taskState.getKvState(i);
            if (keyGroupState != null) {
                dos.write(i);
                SerializedValue<?> serializedValue = keyGroupState.getKeyGroupState();
                if (serializedValue == null) {
                    // null
                    dos.writeInt(-1);
                } else {
                    byte[] serialized = serializedValue.getByteArray();
                    dos.writeInt(serialized.length);
                    dos.write(serialized, 0, serialized.length);
                }
                dos.writeLong(keyGroupState.getStateSize());
                dos.writeLong(keyGroupState.getDuration());
            }
        }
    }
}
Also used : SubtaskState(org.apache.flink.migration.runtime.checkpoint.SubtaskState) TaskState(org.apache.flink.migration.runtime.checkpoint.TaskState) KeyGroupState(org.apache.flink.migration.runtime.checkpoint.KeyGroupState) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState) TaskState(org.apache.flink.migration.runtime.checkpoint.TaskState) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 30 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class RocksDBStateBackend method resetRocksDBLoadedFlag.

@VisibleForTesting
static void resetRocksDBLoadedFlag() throws Exception {
    final Field initField = org.rocksdb.NativeLibraryLoader.class.getDeclaredField("initialized");
    initField.setAccessible(true);
    initField.setBoolean(null, false);
}
Also used : Field(java.lang.reflect.Field) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)64 HashMap (java.util.HashMap)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 Configuration (org.apache.flink.configuration.Configuration)7 Map (java.util.Map)6 File (java.io.File)5 URI (java.net.URI)4 List (java.util.List)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 Field (java.lang.reflect.Field)3 Set (java.util.Set)3 Nullable (javax.annotation.Nullable)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Matcher (java.util.regex.Matcher)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)2