use of org.opensearch.ad.caching.CacheProvider in project anomaly-detection by opensearch-project.
the class ProfileTransportActionTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
modelManager = mock(ModelManager.class);
featureManager = mock(FeatureManager.class);
when(featureManager.getShingleSize(any(String.class))).thenReturn(shingleSize);
EntityCache cache = mock(EntityCache.class);
cacheProvider = mock(CacheProvider.class);
when(cacheProvider.get()).thenReturn(cache);
when(cache.getActiveEntities(anyString())).thenReturn(activeEntities);
when(cache.getTotalUpdates(anyString())).thenReturn(totalUpdates);
Map<String, Long> multiEntityModelSizeMap = new HashMap<>();
String modelId1 = "T4c3dXUBj-2IZN7itix__entity_app_3";
String modelId2 = "T4c3dXUBj-2IZN7itix__entity_app_2";
multiEntityModelSizeMap.put(modelId1, multiEntityModelSize);
multiEntityModelSizeMap.put(modelId2, multiEntityModelSize);
when(cache.getModelSize(anyString())).thenReturn(multiEntityModelSizeMap);
List<ModelProfile> modelProfiles = new ArrayList<>();
String field = "field";
String fieldVal1 = "value1";
String fieldVal2 = "value2";
Entity entity1 = Entity.createSingleAttributeEntity(field, fieldVal1);
Entity entity2 = Entity.createSingleAttributeEntity(field, fieldVal2);
modelProfiles.add(new ModelProfile(modelId1, entity1, multiEntityModelSize));
modelProfiles.add(new ModelProfile(modelId1, entity2, multiEntityModelSize));
when(cache.getAllModelProfile(anyString())).thenReturn(modelProfiles);
Map<String, Long> modelSizes = new HashMap<>();
modelSizes.put(modelId, modelSize);
when(modelManager.getModelSize(any(String.class))).thenReturn(modelSizes);
Settings settings = Settings.builder().put("plugins.anomaly_detection.max_model_size_per_node", 100).build();
action = new ProfileTransportAction(client().threadPool(), clusterService(), mock(TransportService.class), mock(ActionFilters.class), modelManager, featureManager, cacheProvider, settings);
profilesToRetrieve = new HashSet<DetectorProfileName>();
profilesToRetrieve.add(DetectorProfileName.COORDINATING_NODE);
}
use of org.opensearch.ad.caching.CacheProvider in project anomaly-detection by opensearch-project.
the class CronTransportActionTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
ThreadPool threadPool = mock(ThreadPool.class);
ClusterService clusterService = mock(ClusterService.class);
localNodeID = "foo";
when(clusterService.localNode()).thenReturn(new DiscoveryNode(localNodeID, buildNewFakeTransportAddress(), Version.CURRENT));
when(clusterService.getClusterName()).thenReturn(new ClusterName("test"));
TransportService transportService = mock(TransportService.class);
ActionFilters actionFilters = mock(ActionFilters.class);
NodeStateManager tarnsportStatemanager = mock(NodeStateManager.class);
ModelManager modelManager = mock(ModelManager.class);
FeatureManager featureManager = mock(FeatureManager.class);
CacheProvider cacheProvider = mock(CacheProvider.class);
EntityCache entityCache = mock(EntityCache.class);
EntityColdStarter entityColdStarter = mock(EntityColdStarter.class);
when(cacheProvider.get()).thenReturn(entityCache);
ADTaskManager adTaskManager = mock(ADTaskManager.class);
action = new CronTransportAction(threadPool, clusterService, transportService, actionFilters, tarnsportStatemanager, modelManager, featureManager, cacheProvider, entityColdStarter, adTaskManager);
}
Aggregations