public Page<Instance> findInstancesByNamespace(String appId, String clusterName, String
      namespaceName, Pageable pageable) {
    Page<InstanceConfig> instanceConfigs = instanceConfigRepository.
        findByConfigAppIdAndConfigClusterNameAndConfigNamespaceNameAndDataChangeLastModifiedTimeAfter(appId, clusterName,
            namespaceName, getValidInstanceConfigDate(), pageable);

    List<Instance> instances = Collections.emptyList();
    if (instanceConfigs.hasContent()) {
      Set<Long> instanceIds = instanceConfigs.getContent().stream().map
          (InstanceConfig::getInstanceId).collect(Collectors.toSet());
      instances = findInstancesByIds(instanceIds);
    }

    return new PageImpl<>(instances, pageable, instanceConfigs.getTotalElements());
  }
@Test
  @Rollback
  public void testFindInstancesByNamespace() throws Exception {
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    String someReleaseKey = "someReleaseKey";
    Date someValidDate = new Date();

    String someAppId = "someAppId";
    String someClusterName = "someClusterName";
    String someDataCenter = "someDataCenter";
    String someIp = "someIp";
    String anotherIp = "anotherIp";

    Instance someInstance = instanceService.createInstance(assembleInstance(someAppId,
        someClusterName, someDataCenter, someIp));
    Instance anotherInstance = instanceService.createInstance(assembleInstance(someAppId,
        someClusterName, someDataCenter, anotherIp));

    prepareInstanceConfigForInstance(someInstance.getId(), someConfigAppId, someConfigClusterName,
        someConfigNamespaceName, someReleaseKey, someValidDate);
    prepareInstanceConfigForInstance(anotherInstance.getId(), someConfigAppId,
        someConfigClusterName,
        someConfigNamespaceName, someReleaseKey, someValidDate);

    Page<Instance> result = instanceService.findInstancesByNamespace(someConfigAppId,
        someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));

    assertEquals(Lists.newArrayList(someInstance, anotherInstance), result.getContent());
  }