Skip to content

Commit 2c36144

Browse files
Expanded Test to look for lazy implementation
1 parent 8697304 commit 2c36144

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,13 @@ public ReadWriteLock getReadWriteLock()
498498
{
499499
return this.readWriteLock;
500500
}
501+
502+
/**
503+
* <b>Warning!</b> Please be very cautious if you access the root object.
504+
* This should only be done if absolutely necessary!
505+
*/
506+
public VersionedRoot getRoot()
507+
{
508+
return root;
509+
}
501510
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/v2_4/LazyEntityData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,9 @@ public Collection<Object> removeAllEntitiesAndReturnObjectsToStore()
186186
this.entitiesById.clear();
187187
return this.getObjectsToStore();
188188
}
189+
190+
public HashMap<ID, Lazy<T>> getNativeLazyEntitiesById()
191+
{
192+
return entitiesById;
193+
}
189194
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Optional;
2425

@@ -37,6 +38,8 @@
3738
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
3839
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations;
3940
import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy;
41+
import software.xdev.spring.data.eclipse.store.repository.root.v2_4.EntityData;
42+
import software.xdev.spring.data.eclipse.store.repository.root.v2_4.LazyEntityData;
4043

4144

4245
@SuppressWarnings("checkstyle:MethodName")
@@ -302,7 +305,6 @@ void lazyClearBeforeSave()
302305
}
303306

304307
@Test
305-
@Disabled("This should work at some point. At least a warning should be displayed.")
306308
void lazyUseEclipseStoreLazy(@Autowired final ObjectWithLazyRepository<SimpleObject> repository)
307309
{
308310
final ObjectWithLazy<SimpleObject> newLazy = new ObjectWithLazy<>();
@@ -515,19 +517,25 @@ void simpleEntityWithIdLazyWrappedRepository_FindById(
515517
void simpleEntityWithIdLazyRepository_FindById(@Autowired final SimpleEntityWithIdLazyRepository repository)
516518
{
517519
final SimpleEntityWithId objectToStore1 = new SimpleEntityWithId(TestData.DUMMY_STRING);
518-
repository.save(objectToStore1);
520+
final Long object1Id = repository.save(objectToStore1).getId();
519521
final SimpleEntityWithId objectToStore2 = new SimpleEntityWithId(TestData.DUMMY_STRING);
520-
repository.save(objectToStore2);
521-
522-
final List<SimpleEntityWithId> all = repository.findAll();
522+
final Long object2Id = repository.save(objectToStore2).getId();
523523

524524
TestUtil.doBeforeAndAfterRestartOfDatastore(
525525
this.configuration,
526526
() -> {
527-
final Optional<SimpleEntityWithId> reloadedObject =
528-
repository.findById(all.get(0).getId());
527+
LazyReferenceManager.get().cleanUp();
528+
final Optional<SimpleEntityWithId> reloadedObject = repository.findById(object1Id);
529529
Assertions.assertTrue(reloadedObject.isPresent());
530530
}
531531
);
532+
final EntityData<SimpleEntityWithId, Long> entityData = this.configuration.getStorageInstance()
533+
.getRoot()
534+
.getCurrentRootData()
535+
.getEntityData(SimpleEntityWithId.class);
536+
final HashMap<Long, Lazy<SimpleEntityWithId>> lazyEntitiesById =
537+
((LazyEntityData<SimpleEntityWithId, Long>)entityData).getNativeLazyEntitiesById();
538+
Assertions.assertTrue(lazyEntitiesById.get(object1Id).isLoaded());
539+
Assertions.assertFalse(lazyEntitiesById.get(object2Id).isLoaded());
532540
}
533541
}

0 commit comments

Comments
 (0)