flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] zentol commented on a change in pull request #9759: [FLINK-14169][history-server] Cleanup expired jobs from history server
Date Fri, 18 Oct 2019 13:23:39 GMT
zentol commented on a change in pull request #9759: [FLINK-14169][history-server] Cleanup expired
jobs from history server
URL: https://github.com/apache/flink/pull/9759#discussion_r336486143
 
 

 ##########
 File path: flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java
 ##########
 @@ -117,45 +124,145 @@ public void testHistoryServerIntegration() throws Exception {
 		for (int x = 0; x < numJobs; x++) {
 			runJob();
 		}
+		final int numLegacyJobs = 1;
 		createLegacyArchive(jmDirectory.toPath());
 
-		CountDownLatch numExpectedArchivedJobs = new CountDownLatch(numJobs + 1);
+		waitForArchivesCreation(numJobs + numLegacyJobs);
 
-		Configuration historyServerConfig = new Configuration();
-		historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_DIRS, jmDirectory.toURI().toString());
-		historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_WEB_DIR, hsDirectory.getAbsolutePath());
-		historyServerConfig.setLong(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_REFRESH_INTERVAL,
100L);
+		CountDownLatch numExpectedArchivedJobs = new CountDownLatch(numJobs + numLegacyJobs);
 
-		historyServerConfig.setInteger(HistoryServerOptions.HISTORY_SERVER_WEB_PORT, 0);
+		Configuration historyServerConfig = createTestConfiguration(false);
 
-		// the job is archived asynchronously after env.execute() returns
-		File[] archives = jmDirectory.listFiles();
-		while (archives == null || archives.length != numJobs + 1) {
-			Thread.sleep(50);
-			archives = jmDirectory.listFiles();
+		HistoryServer hs =
+		new HistoryServer(
+			historyServerConfig,
+			(event) -> {
+				if (event.getType() == HistoryServerArchiveFetcher.ArchiveEventType.CREATED) {
+					numExpectedArchivedJobs.countDown();
+				}
+			});
+
+		try {
+			hs.start();
+			String baseUrl = "http://localhost:" + hs.getWebPort();
+			numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS);
+
+			ObjectMapper mapper = new ObjectMapper();
+			Assert.assertEquals(numJobs + numLegacyJobs, getJobsOverview(baseUrl, mapper).getJobs().size());
+
+		} finally {
+			hs.stop();
+		}
+	}
+
+	@Test
+	public void testCleanExpiredJob() throws Exception {
+		runArchiveExpirationTest(true);
+	}
+
+	@Test
+	public void testRemainExpiredJob() throws Exception {
+		runArchiveExpirationTest(false);
+	}
+
+	private void runArchiveExpirationTest(boolean cleanupExpiredJobs) throws Exception {
+		int numExpiredJobs = cleanupExpiredJobs ? 1 : 0;
+		int numJobs = 3;
+		List<String> jobIDs = new ArrayList<>();
+		for (int x = 0; x < numJobs; x++) {
+			jobIDs.add(runJob());
 		}
+		waitForArchivesCreation(numJobs);
+
+		CountDownLatch numExpectedArchivedJobs = new CountDownLatch(numJobs);
+		CountDownLatch numExpectedExpiredJobs = new CountDownLatch(numExpiredJobs);
+
+		Configuration historyServerConfig = createTestConfiguration(cleanupExpiredJobs);
+
+		HistoryServer hs =
+			new HistoryServer(
+				historyServerConfig,
+				(event) -> {
+					switch (event.getType()){
+						case CREATED:
+							numExpectedArchivedJobs.countDown();
+							break;
+						case DELETED:
+							numExpectedExpiredJobs.countDown();
+							break;
+					}
+				});
 
-		HistoryServer hs = new HistoryServer(historyServerConfig, numExpectedArchivedJobs);
 		try {
 			hs.start();
+			// check that expected count of archives exists
 
 Review comment:
   seems redundant?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message