content: package org.flexlb.sync.runner;
  
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.concurrent.atomic.LongAdder;
  
  import org.flexlb.cache.service.CacheAwareService;
  import org.flexlb.dao.master.WorkerStatus;
  import org.flexlb.dao.route.RoleType;
  import org.flexlb.engine.grpc.EngineRpcService;
  import org.flexlb.service.grpc.EngineGrpcService;
  import org.flexlb.service.monitor.EngineHealthReporter;
  import org.junit.jupiter.api.Test;
  import org.mockito.Mockito;
  
  import static org.mockito.ArgumentMatchers.any;
  import static org.mockito.ArgumentMatchers.anyInt;
  import static org.mockito.ArgumentMatchers.anyLong;
  import static org.mockito.ArgumentMatchers.anyString;
  import static org.mockito.ArgumentMatchers.eq;
  import static org.mockito.Mockito.times;
  import static org.mockito.Mockito.verify;
  import static org.mockito.Mockito.when;
  
  class GrpcCacheStatusCheckRunnerTest {
  
      private final EngineGrpcService engineGrpcService = Mockito.mock(EngineGrpcService.class);
  
      private final EngineHealthReporter engineHealthReporter = Mockito.mock(EngineHealthReporter.class);
  
      private final CacheAwareService localKvCacheAwareManager = Mockito.mock(CacheAwareService.class);
  
      private final ConcurrentHashMap<String, WorkerStatus> workerStatuses = new ConcurrentHashMap<>();
  
      @Test
      void testGrpcCacheStatusCheckRunner() {
          // Arrange
          String modelName = "test-model";
          String ipPort = "127.0.0.1:8080";
          String site = "test-site";
  
          EngineRpcService.CacheStatusPB cacheStatusPB = EngineRpcService.CacheStatusPB.newBuilder()
                  .setVersion(1)
                  .setAvailableKvCache(1000)
                  .setTotalKvCache(2000)
                  .setBlockSize(128)
                  .build();
          when(engineGrpcService.getCacheStatus(anyString(), anyInt(), any(WorkerStatus.class), anyLong(), anyLong())).thenReturn(cacheStatusPB);
  
          // Act
          GrpcCacheStatusCheckRunner runner = new GrpcCacheStatusCheckRunner(
                  modelName, ipPort, site, RoleType.PREFILL, workerStatuses, engineHealthReporter, engineGrpcService, localKvCacheAwareManager, 20,
                  new LongAdder(), 50L);
          runner.run();
  
          // Give some time for async execution
          try {
              Thread.sleep(100);
          } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
          }
  
          // Assert
          verify(engineGrpcService, times(1)).getCacheStatus(eq("127.0.0.1"), eq(8081), any(WorkerStatus.class), eq(-1L), eq(20L));
      }
  }