Skip to content

Commit

Permalink
test failing due to node closed
Browse files Browse the repository at this point in the history
  • Loading branch information
eirsep committed Jun 1, 2024
1 parent e4c3cbd commit 42372a0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void createIndexIfNotExists(final ActionListener<Void> listener) {
}
final CreateIndexRequest createIndexRequest = new CreateIndexRequest(INDEX_NAME).mapping(getIndexMapping())
.settings(SecurityAnalyticsPlugin.TIF_JOB_INDEX_SETTING);
StashedThreadContext.run(client, () -> client.admin().indices().create(createIndexRequest, ActionListener.wrap(
client.admin().indices().create(createIndexRequest, ActionListener.wrap(
r -> {
log.debug("Ioc match index created");
listener.onResponse(null);
Expand All @@ -146,7 +146,7 @@ public void createIndexIfNotExists(final ActionListener<Void> listener) {
log.error("Failed to create security analytics threat intel job index", e);
listener.onFailure(e);
}
)));
));
} catch (Exception e) {
log.error("Failure in creating ioc_match index", e);
listener.onFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
);
}

settings

@Override
protected boolean ignoreExternalCluster() {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.opensearch.securityanalytics.threatIntel.iocscan.dao;

import org.opensearch.action.LatchedActionListener;
import org.opensearch.action.StepListener;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.common.util.concurrent.CountDown;
import org.opensearch.core.action.ActionListener;
import org.opensearch.securityanalytics.SecurityAnalyticsIntegTestCase;
import org.opensearch.securityanalytics.model.threatintel.IocMatch;
import org.opensearch.test.OpenSearchIntegTestCase;

import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -15,22 +16,33 @@

public class IocMatchServiceIT extends SecurityAnalyticsIntegTestCase {

public void test_indexIocMatches() {
public void test_indexIocMatches() throws InterruptedException {
IocMatchService service = new IocMatchService(client(), clusterService());
List<IocMatch> iocMatches = generateIocMatches(10);
CountDownLatch latch = new CountDownLatch(1);
service.indexIocMatches(iocMatches, new LatchedActionListener<>(new ActionListener<>() {
@Override
public void onResponse(Void unused) {
client().search(new SearchRequest(IocMatchService.INDEX_NAME)).
}
CountDown countdown = new CountDown(1);
service.indexIocMatches(iocMatches, ActionListener.wrap(r -> {
countdown.countDown();
}, e -> {
logger.error("failed to index ioc matches", e);
fail();
countdown.countDown();
}));
SearchRequest request = new SearchRequest(IocMatchService.INDEX_NAME);
request.source().size(10);
CountDown countDownLatch1 = new CountDown(1);
client().search(request, ActionListener.wrap(
response -> {
assertEquals(response.getHits().getHits().length, 10);
countDownLatch1.countDown();
},
e -> {
logger.error("failed to search indexed ioc matches", e);
fail();
countDownLatch1.countDown();
}

@Override
public void onFailure(Exception e) {
logger.error("failed to index ioc matches", e);
fail();
}
}, latch));
));
countDownLatch1.isCountedDown();
}

private List<IocMatch> generateIocMatches(int i) {
Expand All @@ -40,8 +52,8 @@ private List<IocMatch> generateIocMatches(int i) {
for (int i1 = 0; i1 < i; i1++) {
iocMatches.add(new IocMatch(
randomAlphaOfLength(10),
randomList(1,10, () -> randomAlphaOfLength(10)),//docids
randomList(1,10, () -> randomAlphaOfLength(10)), //feedids
randomList(1, 10, () -> randomAlphaOfLength(10)),//docids
randomList(1, 10, () -> randomAlphaOfLength(10)), //feedids
monitorId,
monitorName,
randomAlphaOfLength(10),
Expand Down

0 comments on commit 42372a0

Please sign in to comment.