how to mock an apache ignite query using mockito

65 Views Asked by At

I have a class and a test class, I am trying to test the result of an ignite cache query in my class by adding a mockito test in my test class. I am having a hard time understanding what needs to be mocked and what query I have to create

  1. is the code portion I am trying to test, based on the data processed, I should be able to retrieve one record (id) being added to the cache. I would like to verify that the record was added successfully.

query is already defined

this code in the class is also part of a method in which return value is void

1)

try (QueryCursor<List<?>> cursor = MyCache.query(query.setArgs(id, startOfDayMillis,      endOfDayMillis))) {
    if (cursor != null) {
         for (List<?> row : cursor) {
             if (row.get(0) instanceof SomeJavaObject) {
                 cacheValue = (SomeJavaObject) row.get(0);
             }
         }
     }
 }

if (cacheValue == null) {
    Session key = new SessionKey(sessionId + "_T7", id, sessionTime);
    SessionObject v = new SessionObject(vin);
    SomeJavaObject value = new SomeJavaObject(sessionId + "_T7", v);
    MyCache.put(key, value); //I am trying to retrieve these values 
} 

when(Gen2NodeUtility.getOrCreateIgniteInstanceByType(IGNITE_CLIENT)).thenReturn(ignite);
when(ignite.cache(SomeConstants.TableName)).thenReturn(MyCache);
               

SqlFieldsQuery sqlQuery = new SqlFieldsQuery(query);
List<List<?>> cacheQuery = MyCache.query(sqlQuery).getAll();
verify(resistT7Cache, times(1)).query(sqlQuery);
0

There are 0 best solutions below