如果我按照这两个测试运行,我会收到错误消息。
第一次测试
@Rule
public GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
@Test
public void findAll() throws Exception {
// Generate a unique in-process server name.
String serverName = InProcessServerBuilder.generateName();
// Create a server, add service, start, and register for automatic graceful shutdown.
grpcCleanup.register(InProcessServerBuilder
.forName(serverName)
.directExecutor()
.addService(new Data(mockMongoDatabase))
.build()
.start());
// Create a client channel and register for automatic graceful shutdown.
RoleServiceGrpc.RoleServiceBlockingStub stub = RoleServiceGrpc.newBlockingStub(
grpcCleanup.register(InProcessChannelBuilder
.forName(serverName)
.directExecutor()
.build()));
RoleOuter.Response response = stub.findAll(Empty.getDefaultInstance());
assertNotNull(response);
}
Run Code Online (Sandbox Code Playgroud)
第二次测试
@Test
public void testFindAll() {
ManagedChannel channel …Run Code Online (Sandbox Code Playgroud) 创建了访问和错误管道或可写流,以便将 console.log 或 console.error 写入文件流。
var fs = require("fs");
var access = fs.createWriteStream('/node.access.log', { flags: 'a' });
var error = fs.createWriteStream('/node.error.log', { flags: 'a' });
process.stdout.pipe(access); // redirect stdout / stderr
process.stderr.pipe(error);
Run Code Online (Sandbox Code Playgroud)
我的期望是每当我这样做console.log或console.error将其写入文件输出流时。
我遇到错误
Error: read ENOTCONN
at Socket._read (net.js:528:20)
at Socket.Readable.read (_stream_readable.js:457:10)
at resume_ (_stream_readable.js:936:12)
at processTicksAndRejections (internal/process/task_queues.js:84:9)
Emitted 'error' event at:
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:84:9) {
errno: 'ENOTCONN',
code: 'ENOTCONN',
syscall: 'read'
}
Run Code Online (Sandbox Code Playgroud) 遇到有关正常关闭 asp.net 核心应用程序的非常过时的信息,有人可以填写更新的信息。
用例:我想在应用程序退出时向 consul 注销。
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
})
.UseStartup<Service>();
Run Code Online (Sandbox Code Playgroud) 尝试使用从异步方法调用的挂起函数来实现对错误的优雅处理,如何捕获挂起方法引发的错误。
suspend fun findById(id: Long): User? {
throw Exception("my exception") // intentionally throwing to simulate error situation.
return userModel.findById(id) // IO, may throw an error
}
Run Code Online (Sandbox Code Playgroud)
调用者部分,通过 IO 线程启动
GlobalScope.launch(Dispatchers.IO) {
try {
var userAsync: Deferred<User?>? = null
arguments?.getLong("id")?.let {
userAsync = async { viewModel?.findById(it) } // async for efficiency as i've other async methods too.
}
val data = userAsync?.await()
withContext(Dispatchers.Main) {
user = data // data binding, populating UI fields of user
}
} catch (exception: Exception) { …Run Code Online (Sandbox Code Playgroud) 简介:我将从JSON模式开始描述期望。请注意,这些角色带有嵌套的对象数组,我正在寻找一种“智能查询”,可以通过一个查询来获取它。
{
"id": 1,
"first": "John",
"roles": [ // Expectation -> array of objects
{
"id": 1,
"name": "admin"
},
{
"id": 2,
"name": "accounts"
}
]
}
Run Code Online (Sandbox Code Playgroud)
用户
+----+-------+
| id | first |
+----+-------+
| 1 | John |
| 2 | Jane |
+----+-------+
Run Code Online (Sandbox Code Playgroud)
角色
+----+----------+
| id | name |
+----+----------+
| 1 | admin |
| 2 | accounts |
| 3 | sales |
+----+----------+
Run Code Online (Sandbox Code Playgroud)
user_role
+---------+---------+
| user_id | role_id |
+---------+---------+
| …Run Code Online (Sandbox Code Playgroud) 我已经关注了这篇文章,但github上的代码无法编译,我认为教程已经过时了。( Configuration = builder.Build();) 抛出错误。那么如何访问从 docker 传递过来的 env 呢?
docker-compose
myproj:
image: mcr.microsoft.com/dotnet/core/sdk:2.2
restart: on-failure
working_dir: /MyProj
command: bash -c "dotnet build MyProj.csproj && dotnet bin/Debug/netcoreapp2.2/MyProj.dll"
ports:
- 5001:5001
- 5000:5000
volumes:
- "./MyProj:/MyProj"
environment:
DATABASE_HOST: database
DATABASE_PASSWORD: Password
Run Code Online (Sandbox Code Playgroud)
启动文件
public Service()
{
Environment.GetEnvironmentVariable("DATABASE_PASSWORD"); // null
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit …Run Code Online (Sandbox Code Playgroud) 我遇到了这个答案,我有兴趣使用 Fake 实现第二个答案。这是另一个。
我并没有真正理解那里的所有概念,我仍在阅读和理解文档,有人可以帮助使用我的代码,我正在尝试访问有关如何使用 Fake/Shim/Stub/Mock 的客户列表吗?
您也可以重写FindAll方法,以防万一它被重构以接受依赖项。
讨论后编辑
public class Data
{
private Func<IDbConnection> Factory { get; }
public Data(Func<IDbConnection> factory)
{
Factory = factory;
}
public IList<Customer> FindAll()
{
using (var connection = Factory.Invoke())
{
const string sql = "SELECT Id, Name FROM Customer";
using (var command = new SqlCommand(sql, (SqlConnection) connection))
{
command.Connection.Open();
using (var reader = command.ExecuteReader())
{
IList<Customer> rows = new List<Customer>();
while (reader.Read())
{
rows.Add(new Customer
{ …Run Code Online (Sandbox Code Playgroud) 这个问题与所有其他问题不同,因为这里可打包对象的列表是在外部通过Intent快速发送的,是在外部即时创建的。
问题:产品是可打包的,但自定义List<Product>不是。如何制作List Parcelable??
产品
public class Product implements Parcelable {
public String id;
public String name;
public Product(String id, String name) {
this.id = id;
this.name = name;
}
@Override
public int describeContents() {
return 0;
}
protected Product(Parcel in) {
id = in.readString();
name = in.readString();
}
public static final Creator<Product> CREATOR = new Creator<Product>() {
@Override
public Product createFromParcel(Parcel in) {
return new Product(in);
}
@Override
public Product[] newArray(int size) {
return new Product[size]; …Run Code Online (Sandbox Code Playgroud) 我查找了这个问题的类似答案,但找不到任何答案。
public void update(String id, String user) {
Document document = Document.parse(user);
UpdateResult result = database.getCollection("user")
.updateOne(Filters.eq("_id", new ObjectId(id)), document);
System.out.println(result);
}
Run Code Online (Sandbox Code Playgroud)
我的 JSON 负载如下所示。
{
"first": "John",
"last": "Doe",
"email": "john@example.com",
}
Run Code Online (Sandbox Code Playgroud)
错误
首先无效的 BSON 字段名称
如果我从有效负载中删除第一个,它会反对最后一个,依此类推。
如何通过docker-composeSQL脚本文件为SQL Server指定初始化数据库脚本?
docker-compose.yml
database:
image: microsoft/mssql-server-linux:2017-latest
container_name: database
ports:
- 1433:1433
volumes:
- /var/opt/mssql
environment:
SA_PASSWORD: "P@55w0rd"
ACCEPT_EULA: "Y"
Run Code Online (Sandbox Code Playgroud)
模式.sql
CREATE TABLE Department
(
Id INT PRIMARY KEY IDENTITY (1, 1),
Name VARCHAR (50) NOT NULL
);
CREATE TABLE Student
(
Id INT PRIMARY KEY IDENTITY (1, 1),
Name VARCHAR (50) NOT NULL
);
CREATE TABLE Course
(
Id INT PRIMARY KEY IDENTITY (1, 1),
Name VARCHAR (50) NOT NULL
);
INSERT INTO Student (Id, Name) VALUES(1, "John …Run Code Online (Sandbox Code Playgroud) android ×2
asp.net-core ×2
c# ×2
docker ×2
java ×2
node.js ×2
ado.net ×1
grpc ×1
grpc-java ×1
javascript ×1
json ×1
kotlin ×1
mocking ×1
mongodb ×1
mstest ×1
mysql ×1
parcelable ×1
sql ×1
sql-server ×1
try-catch ×1