Skip to content

Commit

Permalink
track time needed for fetching XML from the RouteCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Dec 5, 2016
1 parent 7908130 commit 0a87965
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Expand Up @@ -20,12 +20,20 @@

package slash.navigation.routes.remote;

import slash.navigation.rest.*;
import slash.navigation.rest.Credentials;
import slash.navigation.rest.Delete;
import slash.navigation.rest.Get;
import slash.navigation.rest.Post;
import slash.navigation.rest.Put;
import slash.navigation.rest.exception.DuplicateNameException;
import slash.navigation.rest.exception.ForbiddenException;
import slash.navigation.rest.exception.ServiceUnavailableException;
import slash.navigation.rest.exception.UnAuthorizedException;
import slash.navigation.routes.*;
import slash.navigation.routes.Catalog;
import slash.navigation.routes.Category;
import slash.navigation.routes.NotFoundException;
import slash.navigation.routes.NotOwnerException;
import slash.navigation.routes.Route;
import slash.navigation.routes.remote.binding.CatalogType;
import slash.navigation.routes.remote.binding.CategoryType;
import slash.navigation.routes.remote.binding.FileType;
Expand Down Expand Up @@ -69,16 +77,22 @@ public Category getRootCategory() {
}

CatalogType fetch(String url) throws IOException {
long start = System.currentTimeMillis();
String urlWithXml = url + FORMAT_XML;
log.info("Fetching from " + urlWithXml);
Get get = new Get(urlWithXml);
String result = get.executeAsString();
if (get.isSuccessful())
try {
return unmarshal(result);
} catch (JAXBException e) {
throw new IOException("Cannot unmarshall " + result + ": " + e, e);
}
try {
Get get = new Get(urlWithXml);
String result = get.executeAsString();
if (get.isSuccessful())
try {
return unmarshal(result);
} catch (JAXBException e) {
throw new IOException("Cannot unmarshall " + result + ": " + e, e);
}
}
finally {
long end = System.currentTimeMillis();
log.info("Fetching from " + urlWithXml + " took " + (end - start) + " milliseconds");
}
return null;
}

Expand Down
Expand Up @@ -135,9 +135,7 @@ public void testSuperuserCanDeleteRouteFromOtherUser() throws IOException {
superUser.deleteRoute(url);

for (Route route : catalog.getRootCategory().getRoutes()) {
if (route.getHref().equals(url)) {
assertTrue("Route " + description + " still exists", false);
}
assertEquals("Route " + description + " still exists", route.getHref(), url);
}
}

Expand Down Expand Up @@ -191,10 +189,15 @@ public void testUpdateRoute() throws IOException {
}

@Test(expected = NotFoundException.class)
public void testCannotUpdateNotExistingRoute() throws IOException {
public void testCannotUpdateNotExistingRouteUrl() throws IOException {
catalog.updateRoute(API + ROUTE_URI + currentTimeMillis() + "/", API, "egal", null, REMOTE_URL);
}

@Test(expected = NotFoundException.class)
public void testCannotUpdateNotExistingRouteFile() throws IOException {
catalog.updateRoute(API + ROUTE_URI + currentTimeMillis() + "/", API, "egal", REMOTE_URL, null);
}

@Test(expected = DuplicateNameException.class)
public void testCannotUpdateRouteWithSameName() throws IOException {
Category root = catalog.getRootCategory();
Expand Down

0 comments on commit 0a87965

Please sign in to comment.