我有一个方法,它在内部调用一个名为“burn”的方法,该方法会引发数据异常,如果是这样,那么它会被捕获在 try/catch 块中并记录到记录器中。然而,该类使用注释 @Slf4j 和 lombok.extern.slf4j:
@Slf4j
public class MyClass {
private void myMethod(Type parameter) throws Exception {
try {
dataGateway.burn(id);
}
catch {
log.error("Failed to burn({})",id);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经模拟了数据网关,并让它在调用 burn 时抛出异常,我知道异常已被捕获,但如何使用验证来断言记录器被调用为 .error?DateGateway dBMock = mock(DateGateway.class);
when(dBMock.burn(anyString())).thenReturn(new DataException("exception"));
Run Code Online (Sandbox Code Playgroud) 我有一个类似的 splunk 查询
index=myIndex* source="source/path/of/logs/*.log" "Elephant"
Run Code Online (Sandbox Code Playgroud)
因此,这会产生大约 2,000 个结果,这些结果是来自我的一个 API 的 JSON 响应,其中包括 world "Elephant"。这正是我想要的 -但是,其中一些结果具有重复carId字段,我只希望 Splunk 向我显示唯一的搜索结果
Splunk 的结果如下所示:
MyApiRequests {"carId":3454353435,"make":"toyota","year":"2015","model":"camry","value":25000.00}
Run Code Online (Sandbox Code Playgroud)
现在,我只想过滤掉那些carId独特的。我不想要重复的。因此,我预计 2,000 个结果的原始值会减少很多。
谁能帮助我制定 Splunk 查询来实现这一目标?
有人可以向我解释一下 build.gradle 文件中“buildscript”中列出的依赖项与依赖项块 { } 中列出的常规依赖项有何不同吗?为什么它们必须用语法“实现”列出?我用谷歌搜索了这个,回复说构建脚本中的依赖项并用于“构建项目”,但我不明白这一点?谁能给出更清晰的图片和答案?
构建脚本:
buildscript
{
repositories
{
maven {
url 'myMavenFeed'
credentials {
username "myUsername"
password myPassword
}
}
mavenCentral()
jcenter()
}
dependencies
{
classpath "com.microsoft.azure.sdk.iot:iot-device-client:1.14.1"
}
}
Run Code Online (Sandbox Code Playgroud)
依赖块:
dependencies
{
compile group: 'com.microsoft.azure.sdk.iot', name: 'iot-device-client', version: '1.16.0'
}
Run Code Online (Sandbox Code Playgroud) 我目前正在学习 Java 中的线程。我想知道在 Java 中发出 Http 请求时的标准协议是什么,它类似于我下面的代码,它使用 Javascript Fetch API 和异步编程。例如,如果我在 Javascript 中使用 Fetch API首先发出GET请求,从 REST 端点获取一些数据,稍后我将使用该数据发出POST请求(如下面的代码所示),我需要使用回调函数或Promise(如下所示)等待第一个请求检索到第二个请求的数据,然后继续。显然,如果我没有使用 Promises 或将第二个 Http POST嵌套在下面的第一个 Fetch 方法 ( GET ) 中,并编写了两个单独的 Fetch API 调用(一个用于GET,一个用于POST,顺序一个接一个又名从上到下) ),两个调用都会同时“触发”,并且第二个POST请求将没有成功POST所需的数据。
const myHttpGETandPOSTmethod = () => {
// First Http request goes here
fetch('http://example.com/movies.json', {
method: 'GET',
headers: // Some headers here,
})
.then(response => response.json())
.then(data …Run Code Online (Sandbox Code Playgroud) 更新:嗯,我在 Bash 脚本中运行它,但我想看看我得到了什么错误代码,现在我可以看到我得到了一个401 Unauthorized. 我正在使用我的用户名并使用admin访问 bitbucket创建了个人访问令牌,所以我应该能够创建一个 PR 对吗?我可以通过同一存储库上的 Web UI 执行此操作吗?
我正在运行 bash 脚本以在 Bitbucket 上创建拉取请求。我已经在以编程方式克隆 repo、编辑文件、执行 git add/commit,现在我只需要使用 CURL 来制作 PR。似乎 bitbucket API 公开了一个端点来使用 POST 请求执行此操作:
Creates a new pull request where the destination repository is this repository and the author is the authenticated user.
The minimum required fields to create a pull request are title and source, specified by a branch name.
curl https://api.bitbucket.org/2.0/repositories/my-username/my-repository/pullrequests \
-u my-username:my-password \
--request POST \
--header 'Content-Type: …Run Code Online (Sandbox Code Playgroud) 我有一些我正在循环的字符串输入,我试图转换为 java 8 流/lambdas,但遇到了一些问题。我的样板代码如下所示:
public static int count(List<String> list) {
String regex = "someRegexPatternHere"
Pattern p = Pattern.compile(regex);
int sum = 0;
for (String val: list) {
Matcher m = p.matcher(val);
if (m.find()) {
// summing logic here
}
}
return sum;
}
Run Code Online (Sandbox Code Playgroud)
我试图做类似的事情
list.stream()
.filter(i -> p.matcher(i).find())
.map(..............)
...
Run Code Online (Sandbox Code Playgroud)
...但无法得到总结逻辑。有人能指出我正确的方向吗?
我试图在常见的 Java 洗牌算法中更好地理解这段代码:
// Random for remaining positions.
int r = i + rand.nextInt(52 - i);
Run Code Online (Sandbox Code Playgroud)
为什么需要“填充”或i向结果随机数添加索引?看起来,当您迭代和添加 时i,通过减去i,您可以将最大可能的随机数范围保持在 0 到 51 之间,但为什么不这样做:
int r = rand.nextInt(52);
Run Code Online (Sandbox Code Playgroud)
完整代码:
// Function which shuffle and print the array
public static void shuffle(int card[], int n)
{
Random rand = new Random();
for (int i = 0; i < n; i++)
{
// Random for remaining positions.
int r = i + rand.nextInt(52 - i);
//swapping the elements …Run Code Online (Sandbox Code Playgroud) java ×3
algorithm ×1
annotations ×1
bitbucket ×1
build-script ×1
classpath ×1
dependencies ×1
git ×1
gradle ×1
java-stream ×1
javascript ×1
lambda ×1
logging ×1
lombok ×1
mockito ×1
pull-request ×1
random ×1
regex ×1
shuffle ×1
slf4j ×1
splunk ×1
unit-testing ×1