Search in sources :

Example 36 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project bazel by bazelbuild.

the class ProtoCompileActionBuilder method createProtoCompilerCommandLine.

/** Commandline generator for protoc invocations. */
@VisibleForTesting
CustomCommandLine.Builder createProtoCompilerCommandLine() throws MissingPrerequisiteException {
    CustomCommandLine.Builder result = CustomCommandLine.builder();
    if (langPluginName == null) {
        if (langParameter != null) {
            result.add(langParameter);
        }
    } else {
        FilesToRunProvider langPluginTarget = getLangPluginTarget();
        Supplier<String> langPluginParameter1 = langPluginParameter == null ? langPluginParameterSupplier : Suppliers.ofInstance(langPluginParameter);
        Preconditions.checkArgument(langParameter == null);
        Preconditions.checkArgument(langPluginParameter1 != null);
        // We pass a separate langPluginName as there are plugins that cannot be overridden
        // and thus we have to deal with "$xx_plugin" and "xx_plugin".
        result.add(String.format("--plugin=protoc-gen-%s=%s", langPrefix, langPluginTarget.getExecutable().getExecPathString()));
        result.add(new LazyLangPluginFlag(langPrefix, langPluginParameter1));
    }
    result.add(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
    boolean areDepsStrict = areDepsStrict(ruleContext);
    // Add include maps
    result.add(new ProtoCommandLineArgv(areDepsStrict ? supportData.getProtosInDirectDeps() : null, supportData.getTransitiveImports()));
    if (areDepsStrict) {
        // Note: the %s in the line below is used by proto-compiler. That is, the string we create
        // here should have a literal %s in it.
        result.add(createStrictProtoDepsViolationErrorMessage(ruleContext.getLabel().getCanonicalForm()));
    }
    for (Artifact src : supportData.getDirectProtoSources()) {
        result.addPath(src.getRootRelativePath());
    }
    if (!hasServices) {
        result.add("--disallow_services");
    }
    if (additionalCommandLineArguments != null) {
        result.add(additionalCommandLineArguments);
    }
    return result;
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) LazyString(com.google.devtools.build.lib.util.LazyString) Artifact(com.google.devtools.build.lib.actions.Artifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 37 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project cassandra by apache.

the class NativeTransportService method initialize.

/**
     * Creates netty thread pools and event loops.
     */
@VisibleForTesting
synchronized void initialize() {
    if (initialized)
        return;
    // prepare netty resources
    eventExecutorGroup = new RequestThreadPoolExecutor();
    if (useEpoll()) {
        workerGroup = new EpollEventLoopGroup();
        logger.info("Netty using native Epoll event loop");
    } else {
        workerGroup = new NioEventLoopGroup();
        logger.info("Netty using Java NIO event loop");
    }
    int nativePort = DatabaseDescriptor.getNativeTransportPort();
    int nativePortSSL = DatabaseDescriptor.getNativeTransportPortSSL();
    InetAddress nativeAddr = DatabaseDescriptor.getRpcAddress();
    org.apache.cassandra.transport.Server.Builder builder = new org.apache.cassandra.transport.Server.Builder().withEventExecutor(eventExecutorGroup).withEventLoopGroup(workerGroup).withHost(nativeAddr);
    if (!DatabaseDescriptor.getClientEncryptionOptions().enabled) {
        servers = Collections.singleton(builder.withSSL(false).withPort(nativePort).build());
    } else {
        if (nativePort != nativePortSSL) {
            // user asked for dedicated ssl port for supporting both non-ssl and ssl connections
            servers = Collections.unmodifiableList(Arrays.asList(builder.withSSL(false).withPort(nativePort).build(), builder.withSSL(true).withPort(nativePortSSL).build()));
        } else {
            // ssl only mode using configured native port
            servers = Collections.singleton(builder.withSSL(true).withPort(nativePort).build());
        }
    }
    // register metrics
    ClientMetrics.instance.addCounter("connectedNativeClients", () -> {
        int ret = 0;
        for (Server server : servers) ret += server.getConnectedClients();
        return ret;
    });
    AuthMetrics.init();
    initialized = true;
}
Also used : RequestThreadPoolExecutor(org.apache.cassandra.transport.RequestThreadPoolExecutor) Server(org.apache.cassandra.transport.Server) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 38 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project cassandra by apache.

the class BatchlogManager method countAllBatches.

@VisibleForTesting
public int countAllBatches() {
    String query = String.format("SELECT count(*) FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.BATCHES);
    UntypedResultSet results = executeInternal(query);
    if (results == null || results.isEmpty())
        return 0;
    return (int) results.one().getLong("count");
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 39 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project cassandra by apache.

the class DatabaseDescriptor method loadConfig.

@VisibleForTesting
public static Config loadConfig() throws ConfigurationException {
    String loaderClass = System.getProperty(Config.PROPERTY_PREFIX + "config.loader");
    ConfigurationLoader loader = loaderClass == null ? new YamlConfigurationLoader() : FBUtilities.<ConfigurationLoader>construct(loaderClass, "configuration loading");
    Config config = loader.loadConfig();
    if (!hasLoggedConfig) {
        hasLoggedConfig = true;
        Config.log(config);
    }
    return config;
}
Also used : AuthConfig(org.apache.cassandra.auth.AuthConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 40 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project cassandra by apache.

the class CommitLogReader method readMutation.

/**
     * Deserializes and passes a Mutation to the ICommitLogReadHandler requested
     *
     * @param handler Handler that will take action based on deserialized Mutations
     * @param inputBuffer raw byte array w/Mutation data
     * @param size deserialized size of mutation
     * @param minPosition We need to suppress replay of mutations that are before the required minPosition
     * @param entryLocation filePointer offset of mutation within CommitLogSegment
     * @param desc CommitLogDescriptor being worked on
     */
@VisibleForTesting
protected void readMutation(CommitLogReadHandler handler, byte[] inputBuffer, int size, CommitLogPosition minPosition, final int entryLocation, final CommitLogDescriptor desc) throws IOException {
    // For now, we need to go through the motions of deserializing the mutation to determine its size and move
    // the file pointer forward accordingly, even if we're behind the requested minPosition within this SyncSegment.
    boolean shouldReplay = entryLocation > minPosition.position;
    final Mutation mutation;
    try (RebufferingInputStream bufIn = new DataInputBuffer(inputBuffer, 0, size)) {
        mutation = Mutation.serializer.deserialize(bufIn, desc.getMessagingVersion(), SerializationHelper.Flag.LOCAL);
        // doublecheck that what we read is still] valid for the current schema
        for (PartitionUpdate upd : mutation.getPartitionUpdates()) upd.validate();
    } catch (UnknownTableException ex) {
        if (ex.id == null)
            return;
        AtomicInteger i = invalidMutations.get(ex.id);
        if (i == null) {
            i = new AtomicInteger(1);
            invalidMutations.put(ex.id, i);
        } else
            i.incrementAndGet();
        return;
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        File f = File.createTempFile("mutation", "dat");
        try (DataOutputStream out = new DataOutputStream(new FileOutputStream(f))) {
            out.write(inputBuffer, 0, size);
        }
        // Checksum passed so this error can't be permissible.
        handler.handleUnrecoverableError(new CommitLogReadException(String.format("Unexpected error deserializing mutation; saved to %s.  " + "This may be caused by replaying a mutation against a table with the same name but incompatible schema.  " + "Exception follows: %s", f.getAbsolutePath(), t), CommitLogReadErrorReason.MUTATION_ERROR, false));
        return;
    }
    if (logger.isTraceEnabled())
        logger.trace("Read mutation for {}.{}: {}", mutation.getKeyspaceName(), mutation.key(), "{" + StringUtils.join(mutation.getPartitionUpdates().iterator(), ", ") + "}");
    if (shouldReplay)
        handler.handleMutation(mutation, size, entryLocation, desc);
}
Also used : UnknownTableException(org.apache.cassandra.exceptions.UnknownTableException) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommitLogReadException(org.apache.cassandra.db.commitlog.CommitLogReadHandler.CommitLogReadException) RebufferingInputStream(org.apache.cassandra.io.util.RebufferingInputStream) Mutation(org.apache.cassandra.db.Mutation) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)808 IOException (java.io.IOException)135 ArrayList (java.util.ArrayList)67 Map (java.util.Map)52 Path (java.nio.file.Path)47 File (java.io.File)41 HashMap (java.util.HashMap)37 Path (org.apache.hadoop.fs.Path)33 List (java.util.List)29 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 HashSet (java.util.HashSet)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 FileStatus (org.apache.hadoop.fs.FileStatus)21 SourcePath (com.facebook.buck.rules.SourcePath)20 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)17 LinkedHashMap (java.util.LinkedHashMap)17