GraphResourceRepository extends GraphGenericRepository<ResourceEntity> implements ResourceRepository, ResourceHierarchicalRepository { @Override public ResourceEntity getByZoneAndResourceIdentifier(final ZoneEntity zone, final String resourceIdentifier) { return getEntity(zone, resourceIdentifier); }  @Override ResourceEntity getByZoneAndResourceIdentifier(final ZoneEntity zone, final String resourceIdentifier); @Override ResourceEntity getResourceWithInheritedAttributes(final ZoneEntity zone, final String resourceIdentifier); @Override Set<String> getResourceEntityAndDescendantsIds(final ResourceEntity entity); @Override List<S> findAll(final Example<S> example); @Override List<S> findAll(final Example<S> example, final Sort sort); @Override S findOne(final Example<S> example); @Override Page<S> findAll(final Example<S> example, final Pageable pageable); @Override long count(final Example<S> example); @Override boolean exists(final Example<S> example); static final String RESOURCE_LABEL; static final String RESOURCE_ID_KEY; }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testGetByZoneAndResourceIdentifier() { ResourceEntity resourceEntity1 = persist2LevelRandomResourcetoZone1(); ResourceEntity resource = this.resourceRepository .getByZoneAndResourceIdentifier(TEST_ZONE_1, resourceEntity1.getResourceIdentifier()); assertThat(resource, equalTo(resourceEntity1)); assertThat(resource.getAttributes().contains(TYPE_MONSTER_OF_THE_WEEK), equalTo(true)); assertThat(resource.getAttributes().contains(SITE_BASEMENT), equalTo(false)); deleteTwoLevelEntityAndParents(resourceEntity1, TEST_ZONE_1, this.resourceRepository); }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testGetByZoneAndResourceIdentifierWithEmptyAttributes() { ResourceEntity persistedResourceEntity = persistResourceToZoneAndAssert(TEST_ZONE_1, DRIVE_ID + getRandomNumber(), Collections.emptySet()); ResourceEntity resource = this.resourceRepository .getByZoneAndResourceIdentifier(TEST_ZONE_1, persistedResourceEntity.getResourceIdentifier()); assertThat(resource, equalTo(persistedResourceEntity)); this.resourceRepository.delete(persistedResourceEntity); }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testGetByZoneAndResourceIdentifierWithNullAttributes() { ResourceEntity persistedResourceEntity = persistResourceToZoneAndAssert(TEST_ZONE_1, DRIVE_ID + getRandomNumber(), null); ResourceEntity resource = this.resourceRepository .getByZoneAndResourceIdentifier(TEST_ZONE_1, persistedResourceEntity.getResourceIdentifier()); assertThat(resource, equalTo(persistedResourceEntity)); this.resourceRepository.delete(persistedResourceEntity); }
@Test(enabled = false) public void testPerformance() throws Exception { for (int i = 0; i < 100000; i++) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); this.resourceRepository.save(new ResourceEntity(TEST_ZONE_1, String.format("/x-files/%d", i))); this.resourceRepository.getByZoneAndResourceIdentifier(TEST_ZONE_1, String.format("/x-files/%d", i)); stopWatch.stop(); System.out.println(String.format("Test %d took: %d ms", i, stopWatch.getTime())); Thread.sleep(1L); } }