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