Skip to content

Commit

Permalink
ISPN-12565 Converts lifespan and maxidle to seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Dec 9, 2020
1 parent 40f82e6 commit 4a6cce5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -207,7 +208,13 @@ private void loadMetadata() {
InternalCacheEntry ice = (InternalCacheEntry) currentEntry;
// add metadata
long lifespan = ice.getLifespan();
if (lifespan > -1) {
lifespan = TimeUnit.MILLISECONDS.toSeconds(lifespan);
}
long maxIdle = ice.getMaxIdle();
if (maxIdle > -1) {
maxIdle = TimeUnit.MILLISECONDS.toSeconds(maxIdle);
}
long created = ice.getCreated();
long lastUsed = ice.getLastUsed();
long expiryTime = ice.getExpiryTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,21 @@ public void testStreamEntriesWithMetadata() {
assertThat(entry).contains("\"expireTime\" : -1");
}

@Test
public void testStreamEntriesWithMetadataAndExpirationTimesConvertedToSeconds() {
RestResponse response = join(client.cache("default").put("key1", "value1", 1000, 5000));
response = join(client.cache("default").entries(1, true));
List<Json> jsons = Json.read(response.getBody()).asJsonList();

assertEquals(1, jsons.size());
Json first = jsons.get(0);
String entry = first.toPrettyString();
assertThat(entry).contains("\"key\" : \"key1");
assertThat(entry).contains("\"value\" : \"value1");
assertThat(entry).contains("\"lifespan\" : 1000");
assertThat(entry).contains("\"maxIdle\" : 5000");
}

@Test
public void testProtobufMetadataManipulation() {
// Special role {@link ProtobufMetadataManager#SCHEMA_MANAGER_ROLE} is needed for authz. Subject USER has it
Expand Down

0 comments on commit 4a6cce5

Please sign in to comment.