|
47 | 47 | import org.apache.http.message.BasicNameValuePair; |
48 | 48 | import org.eclipse.rdf4j.common.io.IOUtil; |
49 | 49 | import org.eclipse.rdf4j.http.protocol.Protocol; |
| 50 | +import org.eclipse.rdf4j.http.server.repository.statements.ExportStatementsView; |
50 | 51 | import org.eclipse.rdf4j.model.IRI; |
51 | 52 | import org.eclipse.rdf4j.model.Namespace; |
52 | 53 | import org.eclipse.rdf4j.model.ValueFactory; |
@@ -93,6 +94,8 @@ public static void stopServer() throws Exception { |
93 | 94 | public void clearRepository() throws Exception { |
94 | 95 | // Clear the repository after each test |
95 | 96 | delete(Protocol.getStatementsLocation(TestServer.REPOSITORY_URL)); |
| 97 | + ExportStatementsView.MAX_NUMBER_OF_STATEMENTS_WHEN_TESTING_FOR_POSSIBLE_EXCEPTIONS = 1024; |
| 98 | + |
96 | 99 | } |
97 | 100 |
|
98 | 101 | /** |
@@ -422,6 +425,94 @@ public void testUploadAndRetrieveStatements_GET() throws Exception { |
422 | 425 |
|
423 | 426 | } |
424 | 427 |
|
| 428 | + @Test |
| 429 | + public void testUploadAndRetrieveStatementsNoValidation_GET() throws Exception { |
| 430 | + |
| 431 | + ExportStatementsView.MAX_NUMBER_OF_STATEMENTS_WHEN_TESTING_FOR_POSSIBLE_EXCEPTIONS = 0; |
| 432 | + |
| 433 | + String statementsLocation = Protocol.getStatementsLocation(TestServer.REPOSITORY_URL); |
| 434 | + |
| 435 | + // PUT the Turtle file into the repository |
| 436 | + final String baseLocation = Protocol.getStatementsLocation(TestServer.REPOSITORY_URL); |
| 437 | + final String file = "/testcases/default-graph-2.ttl"; |
| 438 | + |
| 439 | + // 1. PUT the same file multiple times so that we would trigger an OOM error when retrieving it if it were not |
| 440 | + // directly written to the http output stream |
| 441 | + for (int i = 1; i <= 20000; i++) { |
| 442 | + IRI context = vf.createIRI("http://example.org/graph" + i); |
| 443 | + putFile(baseLocation, file, context); |
| 444 | + } |
| 445 | + |
| 446 | + // GET all statements back from the same endpoint |
| 447 | + URL url = new URL(statementsLocation); |
| 448 | + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| 449 | + conn.setRequestMethod("GET"); |
| 450 | + conn.setRequestProperty("Accept", RDFFormat.NQUADS.getDefaultMIMEType()); // ask for easy-to-parse format |
| 451 | + conn.connect(); |
| 452 | + |
| 453 | + try { |
| 454 | + assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode(), |
| 455 | + "GET /statements should respond 200 OK"); |
| 456 | + |
| 457 | + // Parse the response stream and count triples |
| 458 | + try (InputStream in = conn.getInputStream()) { |
| 459 | + Scanner scanner = new Scanner(in); |
| 460 | + int count = 0; |
| 461 | + while (scanner.hasNext()) { |
| 462 | + scanner.nextLine(); |
| 463 | + count++; |
| 464 | + } |
| 465 | + assertEquals(1860000, count, "Expected 1860000 triples, but got " + count + " instead."); |
| 466 | + } |
| 467 | + } finally { |
| 468 | + conn.disconnect(); |
| 469 | + } |
| 470 | + |
| 471 | + } |
| 472 | + |
| 473 | + @Test |
| 474 | + public void testUploadAndRetrieveStatementsWithFullValidation_GET() throws Exception { |
| 475 | + |
| 476 | + ExportStatementsView.MAX_NUMBER_OF_STATEMENTS_WHEN_TESTING_FOR_POSSIBLE_EXCEPTIONS = -1; |
| 477 | + |
| 478 | + String statementsLocation = Protocol.getStatementsLocation(TestServer.REPOSITORY_URL); |
| 479 | + |
| 480 | + String baseLocation = Protocol.getStatementsLocation(TestServer.REPOSITORY_URL); |
| 481 | + String file = "/testcases/default-graph-2.ttl"; |
| 482 | + |
| 483 | + // PUT the Turtle file into the repository |
| 484 | + for (int i = 1; i <= 2000; i++) { |
| 485 | + IRI context = vf.createIRI("http://example.org/graph" + i); |
| 486 | + putFile(baseLocation, file, context); |
| 487 | + } |
| 488 | + |
| 489 | + // GET all statements back from the same endpoint |
| 490 | + URL url = new URL(statementsLocation); |
| 491 | + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| 492 | + conn.setRequestMethod("GET"); |
| 493 | + conn.setRequestProperty("Accept", RDFFormat.NQUADS.getDefaultMIMEType()); // ask for easy-to-parse format |
| 494 | + conn.connect(); |
| 495 | + |
| 496 | + try { |
| 497 | + assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode(), |
| 498 | + "GET /statements should respond 200 OK"); |
| 499 | + |
| 500 | + // Parse the response stream and count triples |
| 501 | + try (InputStream in = conn.getInputStream()) { |
| 502 | + Scanner scanner = new Scanner(in); |
| 503 | + int count = 0; |
| 504 | + while (scanner.hasNext()) { |
| 505 | + scanner.nextLine(); |
| 506 | + count++; |
| 507 | + } |
| 508 | + assertEquals(186000, count, "Expected 186000 triples, but got " + count + " instead."); |
| 509 | + } |
| 510 | + } finally { |
| 511 | + conn.disconnect(); |
| 512 | + } |
| 513 | + |
| 514 | + } |
| 515 | + |
425 | 516 | /** |
426 | 517 | * Test for SES-1861 |
427 | 518 | * |
|
0 commit comments