/** * Returns a full representation for a given variant. * * @param variant the requested variant of this representation * @return the representation of this resource * @throws ResourceException when the requested resource cannot be represented as requested. */ @Override public Representation represent(Variant variant) throws ResourceException { String xmlString; // If credentials are provided, they need to be valid if (!isAnonymous() && !validateCredentials()) { return null; } // First check if source in URI exists if (validateKnownSource()) { Source source = dbManager.getSource(uriSource); // If source is private, check if current user is allowed to view if ((!source.isPublic()) && (!validateSourceOwnerOrAdmin())) { return null; } // If we make it here, we're all clear to send the XML: either source is public or source is // private but user is authorized to GET. if (variant.getMediaType().equals(MediaType.TEXT_XML)) { try { xmlString = getSourceSummary(); } catch (JAXBException e) { setStatusInternalError(e); return null; } return getStringRepresentation(xmlString); } // Some MediaType other than text/xml requested else { return null; } } else { // unknown source return null; } }
/** * Starts the server going for these tests. * * @throws Exception If problems occur setting up the server. */ @BeforeClass public static void setupServer() throws Exception { ParallelStressTest.server = Server.newTestInstance(); ParallelStressTest.adminEmail = server.getServerProperties().get(ADMIN_EMAIL_KEY); ParallelStressTest.adminPassword = server.getServerProperties().get(ADMIN_PASSWORD_KEY); ParallelStressTest.manager = (DbManager) server.getContext().getAttributes().get("DbManager"); String adminUserUri = manager.getUser(adminEmail).toUri(server); System.out.print("Creating test data..."); ParallelStressTest.START_TIMESTAMP = Tstamp.makeTimestamp("2010-01-08T00:00:00.000-10:00"); ParallelStressTest.END_TIMESTAMP = Tstamp.makeTimestamp("2010-02-08T00:00:00.000-10:00"); SubSources subSources = new SubSources(); for (int i = 0; i < NUM_SOURCES; i++) { Source source = new Source(sourceNames[i], adminUserUri, true); source.addProperty(new Property(Source.SUPPORTS_ENERGY_COUNTERS, "true")); sources[i] = source; sourceURIs[i] = source.toUri(server); subSources.getHref().add(sourceURIs[i]); ParallelStressTest.manager.storeSource(source); } ParallelStressTest.virtualSource = new Source(source11Name, adminUserUri, true, true, "", "", "", null, subSources); ParallelStressTest.manager.storeSource(virtualSource); Date testStart = new Date(); parallelLoad(TEST_CLIENTS, START_TIMESTAMP, END_TIMESTAMP, 15); Date testEnd = new Date(); double msElapsed = testEnd.getTime() - testStart.getTime(); System.out.format("Time to insert data: %.1f ms%n", msElapsed); }