@Override public void close() throws DataStoreException { delegate.close(); cache.invalidateAll(); closeQuietly(tracker); }
@Nullable @Override public DataRecord apply(@Nullable DataIdentifier input) { try { return delegate.getRecord(input); } catch (DataStoreException e) { log.warn("Error occurred while fetching DataRecord for identifier {}", input, e); } return null; } });
/** * Delete objects that have a modified date older than the specified date * from the archive data store. * * @param min * the minimum time * @return the number of data records deleted * @throws DataStoreException */ public int deleteAllOlderThan(long min) throws DataStoreException { return archiveDataStore.deleteAllOlderThan(min); }
byte[] data = new byte[dataLength]; random.nextBytes(data); DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data)); DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data)); ds.updateModifiedDateOnAccess(updateTime); data = new byte[dataLength]; random.nextBytes(data); DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data)); DataRecord rec4 = ds.addRecord(new ByteArrayInputStream(data)); rec1 = ds.getRecord(rec1.getIdentifier()); ds.clearInUse(); Assert.assertEquals("only rec2 should be deleted", 1, ds.deleteAllOlderThan(updateTime)); assertNull("rec2 should be null", ds.getRecordIfStored(rec2.getIdentifier())); Iterator<DataIdentifier> itr = ds.getAllIdentifiers(); List<DataIdentifier> list = new ArrayList<DataIdentifier>(); list.add(rec1.getIdentifier());
/** * Test {@link DataStore#getRecord(DataIdentifier)} and assert length and * inputstream. */ protected void doGetRecordTest() throws Exception { ds = createDataStore(); byte[] data = new byte[dataLength]; randomGen.nextBytes(data); DataRecord rec = ds.addRecord(new ByteArrayInputStream(data)); rec = ds.getRecord(rec.getIdentifier()); assertEquals(data.length, rec.getLength()); assertRecord(data, rec); ds.close(); }
/** * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}. */ protected void doDeleteRecordTest() throws Exception { Random random = randomGen; byte[] data1 = new byte[dataLength]; random.nextBytes(data1); DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1)); byte[] data2 = new byte[dataLength]; random.nextBytes(data2); DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2)); byte[] data3 = new byte[dataLength]; random.nextBytes(data3); DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3)); ((MultiDataStoreAware)ds).deleteRecord(rec1.getIdentifier()); assertNull("rec1 should be null", ds.getRecordIfStored(rec1.getIdentifier())); assertEquals(new ByteArrayInputStream(data2), ds.getRecord(rec2.getIdentifier()).getStream()); assertEquals(new ByteArrayInputStream(data3), ds.getRecord(rec3.getIdentifier()).getStream()); }
@Test public void testReference() throws DataStoreException, IOException { String reference = "testReference"; String blobId = "test"; DataIdentifier testDI = new DataIdentifier(blobId); DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR); when(mockedDS.getRecord(testDI)).thenReturn(testDR); when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); assertEquals(reference,ds.getReference(blobId)); assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId); assertEquals(BlobId.of(testDR).encodedValue(),ds.getBlobId(reference)); String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes()) .getIdentifier().toString(); //For in memory record the reference should be null assertNull(ds.getReference(inMemBlobId)); }
@Override public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException { if (delegate instanceof TypedDataStore) { return ((TypedDataStore) delegate).addRecord(input, options); } return delegate.addRecord(input); }
/** * Test if record can be accessed via * {@link DataStore#getRecordFromReference(String)} */ protected void doReferenceTest() throws Exception { ds = createDataStore(); byte[] data = new byte[dataLength]; randomGen.nextBytes(data); String reference; DataRecord record = ds.addRecord(new ByteArrayInputStream(data)); reference = record.getReference(); assertReference(data, reference, ds); ds.close(); }
/** * Test {@link DataStore#getRecord(DataIdentifier)} and assert length and * inputstream. */ protected void doGetRecordTest() throws Exception { byte[] data = new byte[dataLength]; randomGen.nextBytes(data); DataRecord rec = ds.addRecord(new ByteArrayInputStream(data)); rec = ds.getRecord(rec.getIdentifier()); Assert.assertEquals(data.length, rec.getLength()); assertRecord(data, rec); }
@Override public BlobStore setUp() { String className = System.getProperty("dataStore"); checkNotNull(className, "No system property named 'dataStore' defined"); try { dataStore = Class.forName(className).asSubclass(DataStore.class).newInstance(); config = getConfig(); configure(dataStore, config); dataStore = configureIfCloudDataStore(className, dataStore, config, unique.toLowerCase(), statisticsProvider); storeDir = new File(basedir, unique); dataStore.init(storeDir.getAbsolutePath()); blobStore = new DataStoreBlobStore(dataStore, true, fdsCacheInMB); configure(blobStore); return blobStore; } catch (Exception e) { throw new IllegalStateException("Cannot instantiate DataStore " + className, e); } }
@Override public void updateModifiedDateOnAccess(long before) { delegate.updateModifiedDateOnAccess(before); }
/** * Get all identifiers from the archive data store. * * @return an iterator over all DataIdentifier objects * @throws DataStoreException * if the list could not be read */ public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException { return archiveDataStore.getAllIdentifiers(); }
public DataRecord getRecordFromReference(String reference) throws DataStoreException { DataRecord record = primaryDataStore.getRecordFromReference(reference); if (record == null) { record = archiveDataStore.getRecordFromReference(reference); } return record; }
/** * {@inheritDoc} */ public void clearInUse() { archiveDataStore.clearInUse(); }
@Test public void assertReferenceKey() throws Exception { byte[] data = new byte[dataLength]; randomGen.nextBytes(data); DataRecord rec = ds.addRecord(new ByteArrayInputStream(data)); Assert.assertEquals(data.length, rec.getLength()); assertRecord(data, rec); DataRecord refRec = ds.getRecordFromReference(rec.getReference()); assertRecord(data, refRec); // Check bytes retrieved from reference.key file File refFile = new File(fsBackendPath, "reference.key"); assertTrue(refFile.exists()); byte[] keyRet = FileUtils.readFileToByteArray(refFile); assertTrue(keyRet.length != 0); }
@Override public String getReference(@NotNull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException { if (delegate instanceof TypedDataStore) { return ((TypedDataStore) delegate).addRecord(input, options); } return delegate.addRecord(input); }
/** * Test {@link DataStore#addRecord(InputStream)} and assert length of added * record. */ protected void doAddRecordTest() throws Exception { ds = createDataStore(); byte[] data = new byte[dataLength]; randomGen.nextBytes(data); DataRecord rec = ds.addRecord(new ByteArrayInputStream(data)); assertEquals(data.length, rec.getLength()); assertRecord(data, rec); ds.close(); }
@Override public BlobStore setUp() { String className = System.getProperty("dataStore"); checkNotNull(className, "No system property named 'dataStore' defined"); try { dataStore = Class.forName(className).asSubclass(DataStore.class).newInstance(); config = getConfig(); configure(dataStore, config); dataStore = configureIfCloudDataStore(className, dataStore, config, unique.toLowerCase(), statisticsProvider); storeDir = new File(basedir, unique); dataStore.init(storeDir.getAbsolutePath()); blobStore = new DataStoreBlobStore(dataStore, true, fdsCacheInMB); configure(blobStore); return blobStore; } catch (Exception e) { throw new IllegalStateException("Cannot instantiate DataStore " + className, e); } }