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;
        }

        //for h2 test
        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());
  }
@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());
  }