Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PagingIterator mechanism and tests #7722

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,41 @@ public PagingIterator(PropertyIteratorBase iterator,
@Override
public boolean hasNext()
{
return (cachedElementStart < totalElementCount);
if (cachedElementList == null)
{
return false;
}

if (cachedElementPointer == cachedElementList.size())
{
try
{
cachedElementList = iterator.getCachedList(cachedElementStart, maxCacheSize);
if (cachedElementList == null || cachedElementList.isEmpty())
{
/*
* Prevents the pointer from being equal to the size of the list, signifying that the list is empty.
*/
cachedElementPointer = -1;
return false;
}

cachedElementPointer = 0;
}
catch (PropertyServerException error)
{
/*
* Problem retrieving next cache. The exception includes a detailed error message,
*/
throw new OCFRuntimeException(OCFErrorCode.PROPERTIES_NOT_AVAILABLE.getMessageDefinition(error.getReportedErrorMessage(),
this.toString()),
this.getClass().getName(),
"next",
error);
}
}

return true;
}


Expand All @@ -184,38 +218,9 @@ public boolean hasNext()
@Override
public ElementBase next()
{
/*
* Check more elements available
*/
if (this.hasNext())
{
ElementBase retrievedElement;

/*
* If the pointer is at the end of the cache then retrieve more content from the property (metadata)
* server.
*/
if (cachedElementPointer == cachedElementList.size())
{
try
{
cachedElementList = iterator.getCachedList(cachedElementStart, maxCacheSize);
cachedElementPointer = 0;
}
catch (PropertyServerException error)
{
/*
* Problem retrieving next cache. The exception includes a detailed error message,
*/
throw new OCFRuntimeException(OCFErrorCode.PROPERTIES_NOT_AVAILABLE.getMessageDefinition(error.getReportedErrorMessage(),
this.toString()),
this.getClass().getName(),
"next",
error);
}
}

retrievedElement = iterator.cloneElement(cachedElementList.get(cachedElementPointer));
ElementBase retrievedElement = iterator.cloneElement(cachedElementList.get(cachedElementPointer));
cachedElementPointer++;
cachedElementStart++;

Expand All @@ -232,9 +237,9 @@ public ElementBase next()
/*
* Throw runtime exception to show the caller they are not using the list correctly.
*/
throw new OCFRuntimeException(OCFErrorCode.NO_MORE_ELEMENTS.getMessageDefinition(this.getClass().getSimpleName()),
this.getClass().getName(),
"next");
throw new OCFRuntimeException(OCFErrorCode.NO_MORE_ELEMENTS.getMessageDefinition(this.getClass().getName()),
this.getClass().getName(),
"next");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,74 +31,6 @@ public SchemaAttributes(int totalElementCount,
int maxCacheSize)
{
super(totalElementCount, maxCacheSize);
// Anonymous class for temporary changing the behaviour of the iterator in the case of SchemaAttributes
// as to not use the "totalElementCount" parameter because its value is always 0
super.pagingIterator = new PagingIterator(this, totalElementCount, maxCacheSize)
{
@Override
public ElementBase next()
{
if (this.hasNext())
{
ElementBase retrievedElement = iterator.cloneElement(cachedElementList.get(cachedElementPointer));
cachedElementPointer++;
cachedElementStart++;

log.debug("Returning next element:");
log.debug("==> totalElementCount: " + totalElementCount);
log.debug("==> cachedElementPointer: " + cachedElementPointer);
log.debug("==> cachedElementStart:" + cachedElementStart);
log.debug("==> maxCacheSize:" + maxCacheSize);

return retrievedElement;
}
else
{
/*
* Throw runtime exception to show the caller they are not using the list correctly.
*/
throw new OCFRuntimeException(OCFErrorCode.NO_MORE_ELEMENTS.getMessageDefinition(this.getClass().getName()),
this.getClass().getName(),
"next");
}
}

@Override
public boolean hasNext()
{
if (cachedElementList == null)
{
return false;
}

if (cachedElementPointer == cachedElementList.size())
{
try
{
cachedElementList = iterator.getCachedList(cachedElementStart, maxCacheSize);
if (cachedElementList == null)
{
return false;
}

cachedElementPointer = 0;
}
catch (PropertyServerException error)
{
/*
* Problem retrieving next cache. The exception includes a detailed error message,
*/
throw new OCFRuntimeException(OCFErrorCode.PROPERTIES_NOT_AVAILABLE.getMessageDefinition(error.getReportedErrorMessage(),
this.toString()),
this.getClass().getName(),
"next",
error);
}
}

return true;
}
};
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ private void validatePropertyIterator(int totalElementCount, int maxCache
}


/**
* Validate that element count is set.
/*
* This test is no longer relevant for SchemaAttributes as in real scenarios the count is no longer calculated.
*/
@Test public void testElementCount()
{
SchemaAttributes propertyIterator = getPropertyIterator(30, 10);

assertTrue(propertyIterator.getElementCount() == 30);

SchemaAttributes clonedPropertyIterator = new MockSchemaAttributes( propertyIterator);

assertTrue(clonedPropertyIterator.getElementCount() == 30);

clonedPropertyIterator = new MockSchemaAttributes( null);

assertTrue(clonedPropertyIterator.getElementCount() == 0);
}
// @Test public void testElementCount()
// {
// SchemaAttributes propertyIterator = getPropertyIterator(30, 10);
//
// assertTrue(propertyIterator.getElementCount() == 30);
//
// SchemaAttributes clonedPropertyIterator = new MockSchemaAttributes( propertyIterator);
//
// assertTrue(clonedPropertyIterator.getElementCount() == 30);
//
// clonedPropertyIterator = new MockSchemaAttributes( null);
//
// assertTrue(clonedPropertyIterator.getElementCount() == 0);
// }


/**
Expand Down