@Test public void testValidateCachingBehavior() throws TException, IOException { try (BookKeeperMetrics bookKeeperMetrics = new BookKeeperMetrics(conf, new MetricRegistry())) { checkValidator(new CoordinatorBookKeeper(conf, bookKeeperMetrics), true); } }
protected boolean validateCachingBehavior() { try { DataGen.populateFile(VALIDATOR_TEST_FILE_PATH); } catch (IOException e) { log.error("Could not create temporary file for testing caching behavior", e); return false; } final File tempFile = new File(VALIDATOR_TEST_FILE_PATH); final long fileLength = tempFile.length(); final long readSize = tempFile.length(); final long fileLastModified = tempFile.lastModified(); CacheStatusRequest request = new CacheStatusRequest(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, fileLength, fileLastModified, VALIDATOR_START_BLOCK, VALIDATOR_END_BLOCK).setClusterType(VALIDATOR_CLUSTER_TYPE); try { CacheStatusResponse response = bookKeeper.getCacheStatus(request); if (response == null || response.getBlocks().isEmpty() || response.getBlocks().get(0).getLocation() != Location.LOCAL) { return false; } final boolean dataRead = bookKeeper.readData( VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, VALIDATOR_READ_OFFSET, Ints.checkedCast(readSize), fileLength, fileLastModified, VALIDATOR_CLUSTER_TYPE).isStatus(); if (!dataRead) { return false; } List<BlockLocation> locations = bookKeeper.getCacheStatus(request).getBlocks(); if (locations.isEmpty() || locations.get(0).getLocation() != Location.CACHED) { return false; } return true; } catch (TException e) { log.error("Unable to validate caching behavior", e); return false; } finally { bookKeeper.invalidateFileMetadata(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME); tempFile.delete(); } }
CachingValidator extends AbstractScheduledService { protected boolean validateCachingBehavior() { try { DataGen.populateFile(VALIDATOR_TEST_FILE_PATH); } catch (IOException e) { log.error("Could not create temporary file for testing caching behavior", e); return false; } final File tempFile = new File(VALIDATOR_TEST_FILE_PATH); final long fileLength = tempFile.length(); final long readSize = tempFile.length(); final long fileLastModified = tempFile.lastModified(); CacheStatusRequest request = new CacheStatusRequest(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, fileLength, fileLastModified, VALIDATOR_START_BLOCK, VALIDATOR_END_BLOCK).setClusterType(VALIDATOR_CLUSTER_TYPE); try { CacheStatusResponse response = bookKeeper.getCacheStatus(request); if (response == null || response.getBlocks().isEmpty() || response.getBlocks().get(0).getLocation() != Location.LOCAL) { return false; } final boolean dataRead = bookKeeper.readData( VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, VALIDATOR_READ_OFFSET, Ints.checkedCast(readSize), fileLength, fileLastModified, VALIDATOR_CLUSTER_TYPE).isStatus(); if (!dataRead) { return false; } List<BlockLocation> locations = bookKeeper.getCacheStatus(request).getBlocks(); if (locations.isEmpty() || locations.get(0).getLocation() != Location.CACHED) { return false; } return true; } catch (TException e) { log.error("Unable to validate caching behavior", e); return false; } finally { bookKeeper.invalidateFileMetadata(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME); tempFile.delete(); } } }
CachingValidator extends AbstractScheduledService { protected boolean validateCachingBehavior() { try { DataGen.populateFile(VALIDATOR_TEST_FILE_PATH); } catch (IOException e) { log.error("Could not create temporary file for testing caching behavior", e); return false; } final File tempFile = new File(VALIDATOR_TEST_FILE_PATH); final long fileLength = tempFile.length(); final long readSize = tempFile.length(); final long fileLastModified = tempFile.lastModified(); CacheStatusRequest request = new CacheStatusRequest(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, fileLength, fileLastModified, VALIDATOR_START_BLOCK, VALIDATOR_END_BLOCK).setClusterType(VALIDATOR_CLUSTER_TYPE); try { CacheStatusResponse response = bookKeeper.getCacheStatus(request); if (response == null || response.getBlocks().isEmpty() || response.getBlocks().get(0).getLocation() != Location.LOCAL) { return false; } final boolean dataRead = bookKeeper.readData( VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, VALIDATOR_READ_OFFSET, Ints.checkedCast(readSize), fileLength, fileLastModified, VALIDATOR_CLUSTER_TYPE).isStatus(); if (!dataRead) { return false; } List<BlockLocation> locations = bookKeeper.getCacheStatus(request).getBlocks(); if (locations.isEmpty() || locations.get(0).getLocation() != Location.CACHED) { return false; } return true; } catch (TException e) { log.error("Unable to validate caching behavior", e); return false; } finally { bookKeeper.invalidateFileMetadata(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME); tempFile.delete(); } } CachingValidator(Configuration conf, BookKeeper bookKeeper, ScheduledExecutorService validationExecutor); }
CachingValidator extends AbstractScheduledService { protected boolean validateCachingBehavior() { try { DataGen.populateFile(VALIDATOR_TEST_FILE_PATH); } catch (IOException e) { log.error("Could not create temporary file for testing caching behavior", e); return false; } final File tempFile = new File(VALIDATOR_TEST_FILE_PATH); final long fileLength = tempFile.length(); final long readSize = tempFile.length(); final long fileLastModified = tempFile.lastModified(); CacheStatusRequest request = new CacheStatusRequest(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, fileLength, fileLastModified, VALIDATOR_START_BLOCK, VALIDATOR_END_BLOCK).setClusterType(VALIDATOR_CLUSTER_TYPE); try { CacheStatusResponse response = bookKeeper.getCacheStatus(request); if (response == null || response.getBlocks().isEmpty() || response.getBlocks().get(0).getLocation() != Location.LOCAL) { return false; } final boolean dataRead = bookKeeper.readData( VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, VALIDATOR_READ_OFFSET, Ints.checkedCast(readSize), fileLength, fileLastModified, VALIDATOR_CLUSTER_TYPE).isStatus(); if (!dataRead) { return false; } List<BlockLocation> locations = bookKeeper.getCacheStatus(request).getBlocks(); if (locations.isEmpty() || locations.get(0).getLocation() != Location.CACHED) { return false; } return true; } catch (TException e) { log.error("Unable to validate caching behavior", e); return false; } finally { bookKeeper.invalidateFileMetadata(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME); tempFile.delete(); } } CachingValidator(Configuration conf, BookKeeper bookKeeper, ScheduledExecutorService validationExecutor); boolean didValidationSucceed(); }
CachingValidator extends AbstractScheduledService { protected boolean validateCachingBehavior() { try { DataGen.populateFile(VALIDATOR_TEST_FILE_PATH); } catch (IOException e) { log.error("Could not create temporary file for testing caching behavior", e); return false; } final File tempFile = new File(VALIDATOR_TEST_FILE_PATH); final long fileLength = tempFile.length(); final long readSize = tempFile.length(); final long fileLastModified = tempFile.lastModified(); CacheStatusRequest request = new CacheStatusRequest(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, fileLength, fileLastModified, VALIDATOR_START_BLOCK, VALIDATOR_END_BLOCK).setClusterType(VALIDATOR_CLUSTER_TYPE); try { CacheStatusResponse response = bookKeeper.getCacheStatus(request); if (response == null || response.getBlocks().isEmpty() || response.getBlocks().get(0).getLocation() != Location.LOCAL) { return false; } final boolean dataRead = bookKeeper.readData( VALIDATOR_TEST_FILE_PATH_WITH_SCHEME, VALIDATOR_READ_OFFSET, Ints.checkedCast(readSize), fileLength, fileLastModified, VALIDATOR_CLUSTER_TYPE).isStatus(); if (!dataRead) { return false; } List<BlockLocation> locations = bookKeeper.getCacheStatus(request).getBlocks(); if (locations.isEmpty() || locations.get(0).getLocation() != Location.CACHED) { return false; } return true; } catch (TException e) { log.error("Unable to validate caching behavior", e); return false; } finally { bookKeeper.invalidateFileMetadata(VALIDATOR_TEST_FILE_PATH_WITH_SCHEME); tempFile.delete(); } } CachingValidator(Configuration conf, BookKeeper bookKeeper, ScheduledExecutorService validationExecutor); boolean didValidationSucceed(); static final String VALIDATOR_TEST_FILE_NAME; static final String VALIDATOR_TEST_FILE_PATH; static final String VALIDATOR_TEST_FILE_PATH_WITH_SCHEME; }