Always set cache type for CacheInfo returned from get cache REST endpoint

Callers don't want to deal with null values for the cache type.

Change-Id: I76bd8b376780343020a1af08bf8d9bfe333211de
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2014-06-24 15:23:52 +02:00
committed by David Pursehouse
parent 4d26918293
commit f11eadcf7b
4 changed files with 24 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ The entries in the map are sorted by cache name.
)]}'
{
"accounts": {
"type": "MEM",
"entries": {
"mem": 4
},
@@ -69,6 +70,7 @@ The entries in the map are sorted by cache name.
}
},
"accounts_byemail": {
"type": "MEM",
"entries": {
"mem": 4
},
@@ -78,6 +80,7 @@ The entries in the map are sorted by cache name.
}
},
"accounts_byname": {
"type": "MEM",
"entries": {
"mem": 4
},
@@ -86,6 +89,7 @@ The entries in the map are sorted by cache name.
}
},
"adv_bases": {
"type": "MEM",
"entries": {},
"hit_ratio": {}
},
@@ -97,6 +101,7 @@ The entries in the map are sorted by cache name.
"hit_ratio": {}
},
"changes": {
"type": "MEM",
"entries": {},
"hit_ratio": {}
},
@@ -145,6 +150,7 @@ The entries in the map are sorted by cache name.
"hit_ratio": {}
},
groups": {
"type": "MEM",
"entries": {
"mem": 27
},
@@ -154,14 +160,17 @@ The entries in the map are sorted by cache name.
}
},
"groups_byinclude": {
"type": "MEM",
"entries": {},
"hit_ratio": {}
},
"groups_byname": {
"type": "MEM",
"entries": {},
"hit_ratio": {}
},
"groups_byuuid": {
"type": "MEM",
"entries": {
"mem": 25
},
@@ -171,10 +180,12 @@ The entries in the map are sorted by cache name.
}
},
"groups_external": {
"type": "MEM",
"entries": {},
"hit_ratio": {}
},
groups_members": {
"type": "MEM",
"entries": {
"mem": 4
},
@@ -184,6 +195,7 @@ The entries in the map are sorted by cache name.
}
},
"permission_sort": {
"type": "MEM",
"entries": {
"mem": 16
},
@@ -192,6 +204,7 @@ The entries in the map are sorted by cache name.
}
},
"plugin_resources": {
"type": "MEM",
"entries": {
"mem": 2
},
@@ -200,6 +213,7 @@ The entries in the map are sorted by cache name.
}
},
"project_list": {
"type": "MEM",
"entries": {
"mem": 1
},
@@ -209,6 +223,7 @@ The entries in the map are sorted by cache name.
}
},
"projects": {
"type": "MEM",
"entries": {
"mem": 35
},
@@ -225,6 +240,7 @@ The entries in the map are sorted by cache name.
"hit_ratio": {}
},
"sshkeys": {
"type": "MEM",
"entries": {
"mem": 1
},
@@ -275,6 +291,7 @@ As result a link:#cache-info[CacheInfo] entity is returned.
)]}'
{
"name": "projects",
"type": "MEM",
"entries": {
"mem": 35
},
@@ -443,7 +460,7 @@ The `CacheInfo` entity contains information about a cache.
not set if returned in a map where the cache name is used as map key|
The cache name. If the cache is defined by a plugin the cache name
includes the plugin name: "<plugin-name>-<cache-name>".
|`type` |not set for in memory caches|
|`type` ||
The type of the cache (`MEM`: in memory cache, `DISK`: disk cache).
|`entries` ||
Information about the entries in the cache as a

View File

@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListCaches.CacheInfo;
import com.google.gerrit.server.config.ListCaches.CacheType;
import org.apache.http.HttpStatus;
import org.junit.Test;
@@ -37,7 +38,7 @@ public class GetCacheIT extends AbstractDaemonTest {
CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertEquals("accounts", result.name);
assertNull(result.type);
assertEquals(CacheType.MEM, result.type);
assertEquals(1, result.entries.mem.longValue());
assertNotNull(result.averageGet);
assertTrue(result.averageGet.endsWith("s"));

View File

@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListCaches.CacheInfo;
import com.google.gerrit.server.config.ListCaches.CacheType;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
@@ -42,7 +43,7 @@ public class ListCachesIT extends AbstractDaemonTest {
assertTrue(result.containsKey("accounts"));
CacheInfo accountsCacheInfo = result.get("accounts");
assertNull(accountsCacheInfo.type);
assertEquals(CacheType.MEM, accountsCacheInfo.type);
assertEquals(1, accountsCacheInfo.entries.mem.longValue());
assertNotNull(accountsCacheInfo.averageGet);
assertTrue(accountsCacheInfo.averageGet.endsWith("s"));

View File

@@ -84,6 +84,8 @@ public class ListCaches implements RestReadView<ConfigResource> {
entries.setDisk(diskStats.size());
entries.setSpace(diskStats.space());
hitRatio.setDisk(diskStats.hitCount(), diskStats.requestCount());
} else {
type = CacheType.MEM;
}
}