我有以下代码:
func Call(ctx context.Context, payload Payload) (Response, error) {
req, err := http.NewRequest(...) // Some code that creates request from payload
ctx, cancel = context.withTimeout(ctx, time.Duration(3) * time.Second)
defer cancel()
return http.DefaultClient.Do(req)
}
Run Code Online (Sandbox Code Playgroud)
如果我没有放入defer cancel()
那里会怎么样? go vet
警告过这个
context.WithTimeout返回的cancel函数应该被调用,而不是被丢弃,以避免上下文泄漏
上下文将如何泄露以及这将产生什么影响?谢谢
我是Gatling(2.1.2)的新手,想要做一个小型原型项目给同事们展示.
根据快速入门页面,有几种方法可以用Gatling运行模拟:
gatling-maven-plugin
maven插件执行模拟.gatling-highcharts-maven-archetype
,创建一个项目,并运行Engine类.我发现了那些问题
对于1,很难为模拟类添加依赖项.我必须弄清楚需要什么罐子并将它们放到lib文件夹中.
对于2,它需要安装maven.
对于3,它只从IDE运行
我只想要一个简单的可执行JAR文件,其中所有依赖项捆绑在一起(我的模拟,加特林和第三方),并从任何机器(如EC2实例)运行它.
有没有办法实现这个目标?
更新1:
我尝试了方法3,但将所有项目文件从test
文件夹移动到main
,并用于maven-assembly-plugin
构建具有依赖项的jar.当我尝试运行该文件时,出现以下错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Engine$.delayedEndpoint$Engine$1(Engine.scala:7)
at Engine$delayedInit$body.apply(Engine.scala:4)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at Engine$.main(Engine.scala:4)
at Engine.main(Engine.scala)
Caused by: java.nio.file.FileSystemNotFoundException
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)
at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
at java.nio.file.Paths.get(Paths.java:143)
at io.gatling.core.util.PathHelper$.uri2path(PathHelper.scala:32)
at IDEPathHelper$.<init>(IDEPathHelper.scala:7)
at IDEPathHelper$.<clinit>(IDEPathHelper.scala)
... 11 more
Run Code Online (Sandbox Code Playgroud)
我想这与Gatling配置有关,但不知道出了什么问题.
我知道我可以使用这个命令$ docker images --tree
来查看Docker图像的图层,但是如何在没有拉动它的情况下为Docker Hub上的图像做到这一点?这样我才能在下载之前知道图像上的内容.
例如,对于Tomcat repo,https://registry.hub.docker.com/_/tomcat/,该网页似乎没有显示图像上的内容.我必须查看Github上的Dockerfile才能找到答案.
更新我看到这个repo https://registry.hub.docker.com/u/tutum/tomcat/有更多选项卡."Dockerfile"选项卡显示了它的创建方式,但似乎只显示了最新版本.没有选择查看其他标签的文件?
我今天刚刚开始写Go(所以0经验),并想知道Go是否支持任何形式的"构建所有源文件",就像mvn install
那样.
我的项目结构是
src
`-github.com
`-myproject
|- package1
| `- main.go
`- package2
|- lib1_used_by_main.go
`- lib2_used_by_main.go
Run Code Online (Sandbox Code Playgroud)
当我做
cd src/github.com/myproject
go build
Run Code Online (Sandbox Code Playgroud)
这失败了no buildable Go source files in src/github.com/myproject
,这是正确的,因为所有源文件都在子包中.
是否有一个命令来构建所有子包,而不是明确地列出每个子包?
我正在尝试通过protobuf序列化/反序列化ActorRef。根据Akka的文档,唯一的方法是将ActorRef转换为String,然后将其转换回远程actor系统。
该文档提到使用an ExtendedActorSystem
进行反序列化(请参阅此处)。但是,尚不清楚如何获取ExtendedActorSystem
:
// Serialize
// (beneath toBinary)
val identifier: String = Serialization.serializedActorPath(theActorRef)
// Then just serialize the identifier however you like
// Deserialize
// (beneath fromBinary)
// ==== Where is this extendedSystem from? ====
val deserializedActorRef = extendedSystem.provider.resolveActorRef(identifier)
// Then just use the ActorRef
Run Code Online (Sandbox Code Playgroud)
编辑
我在这里找到了这个问题:Akka(JVM):在另一条消息中使用protobuf序列化actorref,其中提到将转换ActorSystem
为ExtendedActorSystem
。这是正确的方法吗?它会一直有效吗?
我有一个使用Resteasy的Web项目(反过来使用Weld)并部署到Tomcat 7.0.22(我在这里放置了特定版本,以防此版本特别针对此版本).
我有一个ServletContextListener,如下所示:
@WebListener
public class ApplicationInitialisationListener implements ServletContextListener {
// create a logger here
@Inject
HealthCheck healthCheck;
@Override
public void contextInitialized(ServletContextEvent event) {
if (healthCheck == null) {
log.error("healthCheck is null");
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
Run Code Online (Sandbox Code Playgroud)
在部署到Tomcat后,healthCheck is null
记录了,我还注意到日志中的这一行:
<2013-11-13 13:27:40,191> <pack> INFO pool-2-thread-1 org.jboss.weld.environment.tomcat7.Tomcat7Container - Tomcat 7 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
Run Code Online (Sandbox Code Playgroud)
问题1:为什么CDI注入在监听器中不可用?
我调查了这个答案,然后说Load on startup …
我正在尝试使用子模块来测试和生成报告,但是遇到了一些问题.
我有以下项目结构:
parent
|-test1
|-test2
Run Code Online (Sandbox Code Playgroud)
和pom.xml parent
看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>parent</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>test1</module>
<module>test2</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<aggregate>true</aggregate>
<reportsDirectories>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
</reportsDirectories>
</configuration>
<reportSets>
<reportSet>
<inherited>false</inherited>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)
我mvn clean install site
用来构建项目,运行测试并生成一个站点(使用maven站点插件,后者又使用maven surefire报告插件生成测试报告).
问题是在执行子模块的pom.xml之前,父pom.xml与所有阶段(清理,安装和站点)一起执行,因此没有来自test1
和test2
聚合的测试报告parent
. …
全输出:
Error: No available formula with the name "dynamodb-local"
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
Error: No formulae found in taps.
Run Code Online (Sandbox Code Playgroud)
自制版1.1.10
操作系统版本10.11.6
谢谢你的帮助
到目前为止,我未能找到有关该主题的良好解释/文档。
我在用
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.9.5.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的代码如下所示:
@Bean
public MongoClientFactoryBean mongo() {
MongoClientFactoryBean mongo = new MongoClientFactoryBean();
mongo.setHost(host);
mongo.setPort(port);
mongo.setCredentials(new MongoCredential[]{MongoCredential.createCredential(username, database, password.toCharArray())});
return mongo;
}
@Bean
public MongoTemplate mongoTemplate(Mongo mongo) throws Exception {
return new MongoTemplate(mongo, database);
}
Run Code Online (Sandbox Code Playgroud)
你知道我应该如何为此配置 SSL?我可以允许无效证书吗?
等效的 mongo 命令行是
mongo --ssl --sslAllowInvalidCertificates --host <host> --port <port>
Run Code Online (Sandbox Code Playgroud) 当我运行此命令
go test -tags integration $(go list ./... | grep -v /vendor/)
Run Code Online (Sandbox Code Playgroud)
对于所有标记有所有测试的软件包,都会失败 // +build !integration
can't load package: build constraints exclude all Go files
Run Code Online (Sandbox Code Playgroud)
有没有办法go test
在这种情况下忽略那些包而不是失败?谢谢
go ×3
java ×3
akka ×1
akka-cluster ×1
docker ×1
dockerfile ×1
dockerhub ×1
dynamo-local ×1
gatling ×1
homebrew ×1
load-testing ×1
maven ×1
mongodb ×1
resteasy ×1
servlets ×1
spring ×1
surefire ×1
tomcat ×1
weld ×1