InstanceService { public Page<Instance> findInstancesByNamespaceAndInstanceAppId(String instanceAppId, String appId, String clusterName, String namespaceName, Pageable pageable) { Page<Object> instanceIdResult = instanceConfigRepository .findInstanceIdsByNamespaceAndInstanceAppId(instanceAppId, appId, clusterName, namespaceName, getValidInstanceConfigDate(), pageable); List<Instance> instances = Collections.emptyList(); if (instanceIdResult.hasContent()) { Set<Long> instanceIds = instanceIdResult.getContent().stream().map((Object o) -> { if (o == null) { return null; } if (o instanceof Integer) { return ((Integer)o).longValue(); } if (o instanceof Long) { return (Long) o; } if (o instanceof BigInteger) { return ((BigInteger) o).longValue(); } return null; }).filter(Objects::nonNull).collect(Collectors.toSet()); instances = findInstancesByIds(instanceIds); } return new PageImpl<>(instances, pageable, instanceIdResult.getTotalElements()); } InstanceService(
      final InstanceRepository instanceRepository,
      final InstanceConfigRepository instanceConfigRepository); Instance findInstance(String appId, String clusterName, String dataCenter, String ip); List<Instance> findInstancesByIds(Set<Long> instanceIds); @Transactional Instance createInstance(Instance instance); InstanceConfig findInstanceConfig(long instanceId, String configAppId, String
      configNamespaceName); Page<InstanceConfig> findActiveInstanceConfigsByReleaseKey(String releaseKey, Pageable
      pageable); Page<Instance> findInstancesByNamespace(String appId, String clusterName, String
      namespaceName, Pageable pageable); Page<Instance> findInstancesByNamespaceAndInstanceAppId(String instanceAppId, String
      appId, String clusterName, String
                                                                     namespaceName, Pageable
                                                                     pageable); List<InstanceConfig> findInstanceConfigsByNamespaceWithReleaseKeysNotIn(String appId,
                                                                                 String clusterName,
                                                                                 String
                                                                                     namespaceName,
                                                                                 Set<String>
                                                                                     releaseKeysNotIn); @Transactional InstanceConfig createInstanceConfig(InstanceConfig instanceConfig); @Transactional InstanceConfig updateInstanceConfig(InstanceConfig instanceConfig); @Transactional int batchDeleteInstanceConfig(String configAppId, String configClusterName, String configNamespaceName);  }
@Test @Rollback public void testFindInstancesByNamespaceAndInstanceAppId() throws Exception { String someConfigAppId = "someConfigAppId"; String someConfigClusterName = "someConfigClusterName"; String someConfigNamespaceName = "someConfigNamespaceName"; String someReleaseKey = "someReleaseKey"; Date someValidDate = new Date(); String someAppId = "someAppId"; String anotherAppId = "anotherAppId"; String someClusterName = "someClusterName"; String someDataCenter = "someDataCenter"; String someIp = "someIp"; Instance someInstance = instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter, someIp)); Instance anotherInstance = instanceService.createInstance(assembleInstance(anotherAppId, someClusterName, someDataCenter, someIp)); prepareInstanceConfigForInstance(someInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate); prepareInstanceConfigForInstance(anotherInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate); Page<Instance> result = instanceService.findInstancesByNamespaceAndInstanceAppId(someAppId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10)); Page<Instance> anotherResult = instanceService.findInstancesByNamespaceAndInstanceAppId(anotherAppId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10)); assertEquals(Lists.newArrayList(someInstance), result.getContent()); assertEquals(Lists.newArrayList(anotherInstance), anotherResult.getContent()); }