Java 8 在这里。我正在尝试获取当前Date(现在),为其添加一天,并获得一个Date代表明天的新实例,该实例没有时间组件(只有年、月和日)。我最好的尝试:
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime();
Run Code Online (Sandbox Code Playgroud)
但是当我打印时tomorrow,它包含一个时间组件(例如Sat Jun 02 14:04:59 EDT 2018:),而我只希望它包含小时/月/分钟/等的归零值(所以:)Sat Jun 02 00:00:00 EDT 2018。我怎样才能做到这一点?归根结底,我只想要一个Date代表明天日期的实例,所以在伪代码中:
Date now = new Date(); // 2018-06-01
Date tomorrow = now.plus(1, DAY); // 2018-06-02
Run Code Online (Sandbox Code Playgroud) 请注意:我创建了这个GitHub项目来帮助您准确地解决问题.
Java 8和Gradle 4.6在这里.如果您通过gradle init --type java-libraryGradle Checkstyle插件创建一个新的Java Gradle项目,并将该插件配置为使用Google的Checkstyle XML,它将立即失败:
plugins {
id 'java-library'
}
apply plugin: 'checkstyle'
dependencies {
testCompile(
'junit:junit:4.12'
)
}
repositories {
jcenter()
mavenCentral()
}
checkstyle {
// Go to the Google Checks link above and paste its
// contents into checkstyle.xml
config = rootProject.resources.text.fromFile('buildConfig/checkstyle/checkstyle.xml')
}
Run Code Online (Sandbox Code Playgroud)
使用该配置,运行./gradle clean build产生:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':checkstyleMain'.
> Unable to …Run Code Online (Sandbox Code Playgroud) 我有以下 Pyhton3/Boto3 脚本,它连接到 AWS DynamoDB 表并尝试通过循环遍历其所有记录来设置 19 天的 TTL:
#!/usr/bin/env python3
import boto3
import sys
from datetime import datetime, timedelta
from boto3.dynamodb.conditions import Key, Attr
client = boto3.resource('dynamodb')
ttl = 19 # The TTL in number of DAYS
myTable = client.Table('MyTable')
pe = "logId, id, created"
delCount = 0
try:
response = integrationLogTable.scan(
ProjectionExpression=pe,
)
while 'LastEvaluatedKey' in response:
response = integrationLogTable.scan(
ProjectionExpression=pe,
ExclusiveStartKey=response['LastEvaluatedKey']
)
for i in response['Items']:
# ???
except ClientError as e:
print(e.response['Error']['Message'])
Run Code Online (Sandbox Code Playgroud)
我正在努力解决如何将 19 天的 TTL …
我有一个使用 ActiveMQ 的应用程序,通常,我通过使用 AMQ 的 Web UI 将消息发送到我的软件正在使用的队列来测试它。
我想对此进行半自动化,并希望 AMQ 的命令行能够通过在命令调用中将该消息作为文本提供,或者理想情况下从文件中读取它来将消息发送到特定队列。
例子:
./activemq-send queue="my-queue" messageFile="~/someMessage.xml"
Run Code Online (Sandbox Code Playgroud)
或者:
./activemq-send queue="my-queue" message="<someXml>...</someXml>"
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我正在 Docker 化一个简单的 Node/JS(NestJS——但我认为这对于这个问题来说并不重要)Web 服务,并且有一些问题。该服务与 Postgres DB 进行通信。我想编写一个Dockerfile可用于构建服务映像(让我们称之为my-service),然后编写一个docker-compose.yml定义 Postgres DB 服务以及my-service使用它的服务的服务。这样我就可以构建镜像,my-service而且还可以有一个 Docker Compose 配置来同时运行服务及其数据库。我认为这就是做到这一点的方法(但请保持诚实!)。Kubernetes 对我来说不是一个选择,仅供参考。
Web 服务具有如下所示的顶级目录结构:
my-service/
.env
package.json
package-lock.json
src/
<lots of other stuff>
Run Code Online (Sandbox Code Playgroud)
值得注意的是,在目前的非容器化形式中,您必须提前设置几个环境变量,包括 Postgres DB 连接信息(主机、端口、数据库名称、用户名、密码等)。应用程序代码在运行时获取这些环境变量的值并使用它们连接到 Postgres。
所以,我需要一种方法来编写Dockerfile这样docker-compose.yml的:
my-service,并且想要告诉它连接到任意 Postgres DB,我可以将这些环境变量作为(理想情况下)Docker CLI 命令上的运行时参数传递(但请记住应用程序)期望它们被设置为环境变量);和my-service,我还需要在 Docker Compose CLI 中将它们指定为运行时参数,然后 Docker Compose 需要将它们传递给容器的运行参数,然后容器需要将它们设置为环境变量以供 Web 服务使用再说一遍,我认为这是正确的方法,但请保持诚实!
所以我最好的尝试——到目前为止的总WIP——看起来像这样:
DockerfileFROM …Run Code Online (Sandbox Code Playgroud) 我有一个 Python DBT 项目,它定义了以下数据模型(通过 YAML):
version: 2
models:
- name: company
description: ''
columns:
- name: ID
description: Unique identifier for the company entity. It is the company name
tests:
- unique
- not_null
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: VARCHAR
- name: REMOTE_ID
description: Company name
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: VARCHAR
- name: CREATED_AT
description: ''
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: TIMESTAMP_TZ
- not_null
- name: UPDATED_AT
description: ''
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: TIMESTAMP_TZ
Run Code Online (Sandbox Code Playgroud)
当我运行时dbt compile,然后dbt run我dbt test …
我过去工作过的大多数团队在使用 Git 时都遵循相同的工作流程(有一些微小的变化):
develop树枝 ( git checkout develop)git checkout -b feature/XYZ-123)git add . && git commit -m "some commit message"),然后返回develop并拉取它 ( git checkout develop && git pull)develop到其中 ( git checkout feature/XYZ-123 && git merge develop)git push -u origin feature/XYZ-123) 并创建 PR我们将其称为“合并方法”。好处是,develop自您创建分支以来所做的任何更改现在都会合并到您的分支中。因此,当您创建 PR 时,不存在合并冲突,develop并且代码审阅者可以看到您的分支和develop.
我现在正在一个团队中工作,该团队在合并步骤之前具有类似的流程,但随后develop他们没有合并到我的功能分支中,而是要求从 …
Java/Akka在这里.我有以下演员:
public class MyActor extends AbstractActor {
private Logger log = LoggerFactory.getLogger(this.getClass());
public MyActor() {
super();
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Init.class, init -> {
log.info("Sending myself a Poison Pill...");
self().tell(PoisonPill.getInstance(), self());
}).match(PoisonPill.class, poisonPill -> {
log.info("Got the Poison Pill...");
context().system().terminate();
}).build();
}
}
Run Code Online (Sandbox Code Playgroud)
收到Init消息后,我看到写入以下日志语句:
Sending myself a Poison Pill...
Run Code Online (Sandbox Code Playgroud)
但我从未见过:
Got the Poison Pill...
Run Code Online (Sandbox Code Playgroud)
此外,该应用程序只是坐在那里,并没有按预期关闭.我使用的是self().tell(PoisonPill.getInstance(), self())什么阻止它接收消息并关闭?
我有一个使用 MySQL 作为后备存储的 Web 服务。我想对该服务及其 MySQL 数据库进行 Docker 化。对于该服务,我有以下 Dockerfile:
FROM openjdk:8-jdk-alpine as cce
COPY build/libs/my-service.jar my-service.jar
EXPOSE 9200
ENTRYPOINT [ \
"java", \
"-Ddb.hostAndPort=my-service-db:3306", \
"-Ddb.name=my_service_db_local", \
"-Ddb.username=my-service-user", \
"-Ddb.password=abc123", \
"-jar", \
"my-service.jar" \
]
Run Code Online (Sandbox Code Playgroud)
如果我正确理解 Docker 生态系统,听起来我可以编写一个 Docker Compose 文件来启动 MySQL 容器实例以及 Web 服务容器实例。所以我docker-compose.yml启动了一个文件,如下所示:
version: "3.7"
services:
my-service-db:
image: mysql:8
container_name: my-service-db
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: r00tdud3
MYSQL_DATABASE: my_service_db_local
MYSQL_USER: my-service-user
MYSQL_PASSWORD: abc123
volumes:
- ./my-service-db-data:/var/lib/mysql
my-service:
??? how to …Run Code Online (Sandbox Code Playgroud) 请注意:我在这里提到了 JUnit 并提供了一个使用它的SSCCE代码示例,但这实际上是一个 Java 集合问题,任何有 Java 经验的人都可以回答,无论他们使用 JUnit 的经验如何。
Java 8 在这里,我正在尝试对字符串列表进行排序,但我从中得到了一些意想不到的行为Collections.sort(myList),我想知道发生了什么。
这是我的完整单元测试:
@RunWith(MockitoJUnitRunner.class)
public class SorterTest {
@Test
public void should_sort_correctly_including_capitalization_rules() {
// given
String[] actualNames = new String[] {
"DCME",
"CCME",
"ACME",
"BCME",
"AGME",
"AACME",
"aCME",
"Acme",
"AaCME",
"aACME",
};
List<String> actual = Arrays.asList(actualNames);
// the order I would *expect* them to sort into...
String[] expectedNames = new String[] {
"aACME",
"aCME",
"AaCME",
"AACME",
"Acme",
"ACME",
"AGME",
"BCME",
"CCME",
"DCME"
};
List<String> expected …Run Code Online (Sandbox Code Playgroud) java ×3
docker ×2
java-8 ×2
akka ×1
bash ×1
boto3 ×1
calendar ×1
checkstyle ×1
collections ×1
date ×1
dbt ×1
dockerfile ×1
git ×1
git-flow ×1
github ×1
gradle ×1
junit ×1
merge ×1
nestjs ×1
node.js ×1
postgresql ×1
python-3.x ×1
sorting ×1
ttl ×1