@Test public void testMissingBlobGet() throws Exception { String key = "foo"; createBlob(key, "SomeContent"); removeAllBlobsFromBlobProvider(); ts.getBlobs(key); }
@Override public List<Blob> getBlobs(String key) { KeyValueStore kvs = getKeyValueStore(); BlobProvider bp = getBlobProvider(); List<String> blobMapJsons = new ArrayList<>(); boolean lockAcquired = tryAcquireBlobLock(key, kvs); try { String info = kvs.getString(key + DOT_BLOBINFO); if (info == null) { if (kvs.getString(key + DOT_COMPLETED) == null) { return null; } else { return Collections.emptyList(); } } Map<String, String> blobInfoMap = jsonToMap(info); String countStr = blobInfoMap.get(COUNT); if (countStr == null) { return Collections.emptyList(); } int count = Integer.parseInt(countStr); for (int i = 0; i < count; i++) { String blobMapJson = kvs.getString(key + DOT_BLOB_DOT + i); blobMapJsons.add(blobMapJson); } } finally { if (lockAcquired) { releaseBlobLock(key, kvs); } } List<Blob> blobs = new ArrayList<>(); for (String blobMapJson : blobMapJsons) { if (blobMapJson == null) { break; } Map<String, String> blobMap = jsonToMap(blobMapJson); String blobKey = blobMap.get(KEY); if (blobKey == null) { break; } String mimeType = blobMap.get(MIMETYPE); String encoding = blobMap.get(ENCODING); String filename = blobMap.get(FILENAME); String lengthStr = blobMap.get(LENGTH); Long length = lengthStr == null ? null : Long.valueOf(lengthStr); String digest = blobMap.get(DIGEST); BlobInfo blobInfo = new BlobInfo(); blobInfo.key = blobKey; blobInfo.mimeType = mimeType; blobInfo.encoding = encoding; blobInfo.filename = filename; blobInfo.length = length; blobInfo.digest = digest; try { Blob blob = bp.readBlob(blobInfo); blobs.add(blob); } catch (IOException e) { log.debug("Failed to read blob: " + digest + " in blob provider: " + blobProviderId + " for transient store: " + name); } } return blobs; }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public List<Blob> getBlobs(String key) { KeyValueStore kvs = getKeyValueStore(); BlobProvider bp = getBlobProvider(); List<String> blobMapJsons = new ArrayList<>(); boolean lockAcquired = tryAcquireBlobLock(key, kvs); try { String info = kvs.getString(key + DOT_BLOBINFO); if (info == null) { if (kvs.getString(key + DOT_COMPLETED) == null) { return null; } else { return Collections.emptyList(); } } Map<String, String> blobInfoMap = jsonToMap(info); String countStr = blobInfoMap.get(COUNT); if (countStr == null) { return Collections.emptyList(); } int count = Integer.parseInt(countStr); for (int i = 0; i < count; i++) { String blobMapJson = kvs.getString(key + DOT_BLOB_DOT + i); blobMapJsons.add(blobMapJson); } } finally { if (lockAcquired) { releaseBlobLock(key, kvs); } } List<Blob> blobs = new ArrayList<>(); for (String blobMapJson : blobMapJsons) { if (blobMapJson == null) { break; } Map<String, String> blobMap = jsonToMap(blobMapJson); String blobKey = blobMap.get(KEY); if (blobKey == null) { break; } String mimeType = blobMap.get(MIMETYPE); String encoding = blobMap.get(ENCODING); String filename = blobMap.get(FILENAME); String lengthStr = blobMap.get(LENGTH); Long length = lengthStr == null ? null : Long.valueOf(lengthStr); String digest = blobMap.get(DIGEST); BlobInfo blobInfo = new BlobInfo(); blobInfo.key = blobKey; blobInfo.mimeType = mimeType; blobInfo.encoding = encoding; blobInfo.filename = filename; blobInfo.length = length; blobInfo.digest = digest; try { Blob blob = bp.readBlob(blobInfo); blobs.add(blob); } catch (IOException e) { log.debug("Failed to read blob: " + digest + " in blob provider: " + blobProviderId + " for transient store: " + name); } } return blobs; } }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public List<Blob> getBlobs(String key) { KeyValueStore kvs = getKeyValueStore(); BlobProvider bp = getBlobProvider(); List<String> blobMapJsons = new ArrayList<>(); boolean lockAcquired = tryAcquireBlobLock(key, kvs); try { String info = kvs.getString(key + DOT_BLOBINFO); if (info == null) { if (kvs.getString(key + DOT_COMPLETED) == null) { return null; } else { return Collections.emptyList(); } } Map<String, String> blobInfoMap = jsonToMap(info); String countStr = blobInfoMap.get(COUNT); if (countStr == null) { return Collections.emptyList(); } int count = Integer.parseInt(countStr); for (int i = 0; i < count; i++) { String blobMapJson = kvs.getString(key + DOT_BLOB_DOT + i); blobMapJsons.add(blobMapJson); } } finally { if (lockAcquired) { releaseBlobLock(key, kvs); } } List<Blob> blobs = new ArrayList<>(); for (String blobMapJson : blobMapJsons) { if (blobMapJson == null) { break; } Map<String, String> blobMap = jsonToMap(blobMapJson); String blobKey = blobMap.get(KEY); if (blobKey == null) { break; } String mimeType = blobMap.get(MIMETYPE); String encoding = blobMap.get(ENCODING); String filename = blobMap.get(FILENAME); String lengthStr = blobMap.get(LENGTH); Long length = lengthStr == null ? null : Long.valueOf(lengthStr); String digest = blobMap.get(DIGEST); BlobInfo blobInfo = new BlobInfo(); blobInfo.key = blobKey; blobInfo.mimeType = mimeType; blobInfo.encoding = encoding; blobInfo.filename = filename; blobInfo.length = length; blobInfo.digest = digest; try { Blob blob = bp.readBlob(blobInfo); blobs.add(blob); } catch (IOException e) { log.debug("Failed to read blob: " + digest + " in blob provider: " + blobProviderId + " for transient store: " + name); } } return blobs; }  }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public List<Blob> getBlobs(String key) { KeyValueStore kvs = getKeyValueStore(); BlobProvider bp = getBlobProvider(); List<String> blobMapJsons = new ArrayList<>(); boolean lockAcquired = tryAcquireBlobLock(key, kvs); try { String info = kvs.getString(key + DOT_BLOBINFO); if (info == null) { if (kvs.getString(key + DOT_COMPLETED) == null) { return null; } else { return Collections.emptyList(); } } Map<String, String> blobInfoMap = jsonToMap(info); String countStr = blobInfoMap.get(COUNT); if (countStr == null) { return Collections.emptyList(); } int count = Integer.parseInt(countStr); for (int i = 0; i < count; i++) { String blobMapJson = kvs.getString(key + DOT_BLOB_DOT + i); blobMapJsons.add(blobMapJson); } } finally { if (lockAcquired) { releaseBlobLock(key, kvs); } } List<Blob> blobs = new ArrayList<>(); for (String blobMapJson : blobMapJsons) { if (blobMapJson == null) { break; } Map<String, String> blobMap = jsonToMap(blobMapJson); String blobKey = blobMap.get(KEY); if (blobKey == null) { break; } String mimeType = blobMap.get(MIMETYPE); String encoding = blobMap.get(ENCODING); String filename = blobMap.get(FILENAME); String lengthStr = blobMap.get(LENGTH); Long length = lengthStr == null ? null : Long.valueOf(lengthStr); String digest = blobMap.get(DIGEST); BlobInfo blobInfo = new BlobInfo(); blobInfo.key = blobKey; blobInfo.mimeType = mimeType; blobInfo.encoding = encoding; blobInfo.filename = filename; blobInfo.length = length; blobInfo.digest = digest; try { Blob blob = bp.readBlob(blobInfo); blobs.add(blob); } catch (IOException e) { log.debug("Failed to read blob: " + digest + " in blob provider: " + blobProviderId + " for transient store: " + name); } } return blobs; }  @Override void init(TransientStoreConfig config); @Override void shutdown(); @Override Stream<String> keyStream(); @Override long getStorageSize(); @Override void doGC(); @Override void removeAll(); @Deprecated void atomicUpdate(String key, Function<String, String> updateFunction, long ttl); @Override boolean exists(String key); @Override void putParameter(String key, String parameter, Serializable value); @Override Serializable getParameter(String key, String parameter); @Override void putParameters(String key, Map<String, Serializable> parameters); @Override Map<String, Serializable> getParameters(String key); @Override void putBlobs(String key, List<Blob> blobs); @Override List<Blob> getBlobs(String key); @Override long getSize(String key); @Override boolean isCompleted(String key); @Override void setCompleted(String key, boolean completed); @Override void release(String key); @Override void remove(String key); }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public List<Blob> getBlobs(String key) { KeyValueStore kvs = getKeyValueStore(); BlobProvider bp = getBlobProvider(); List<String> blobMapJsons = new ArrayList<>(); boolean lockAcquired = tryAcquireBlobLock(key, kvs); try { String info = kvs.getString(key + DOT_BLOBINFO); if (info == null) { if (kvs.getString(key + DOT_COMPLETED) == null) { return null; } else { return Collections.emptyList(); } } Map<String, String> blobInfoMap = jsonToMap(info); String countStr = blobInfoMap.get(COUNT); if (countStr == null) { return Collections.emptyList(); } int count = Integer.parseInt(countStr); for (int i = 0; i < count; i++) { String blobMapJson = kvs.getString(key + DOT_BLOB_DOT + i); blobMapJsons.add(blobMapJson); } } finally { if (lockAcquired) { releaseBlobLock(key, kvs); } } List<Blob> blobs = new ArrayList<>(); for (String blobMapJson : blobMapJsons) { if (blobMapJson == null) { break; } Map<String, String> blobMap = jsonToMap(blobMapJson); String blobKey = blobMap.get(KEY); if (blobKey == null) { break; } String mimeType = blobMap.get(MIMETYPE); String encoding = blobMap.get(ENCODING); String filename = blobMap.get(FILENAME); String lengthStr = blobMap.get(LENGTH); Long length = lengthStr == null ? null : Long.valueOf(lengthStr); String digest = blobMap.get(DIGEST); BlobInfo blobInfo = new BlobInfo(); blobInfo.key = blobKey; blobInfo.mimeType = mimeType; blobInfo.encoding = encoding; blobInfo.filename = filename; blobInfo.length = length; blobInfo.digest = digest; try { Blob blob = bp.readBlob(blobInfo); blobs.add(blob); } catch (IOException e) { log.debug("Failed to read blob: " + digest + " in blob provider: " + blobProviderId + " for transient store: " + name); } } return blobs; }  @Override void init(TransientStoreConfig config); @Override void shutdown(); @Override Stream<String> keyStream(); @Override long getStorageSize(); @Override void doGC(); @Override void removeAll(); @Deprecated void atomicUpdate(String key, Function<String, String> updateFunction, long ttl); @Override boolean exists(String key); @Override void putParameter(String key, String parameter, Serializable value); @Override Serializable getParameter(String key, String parameter); @Override void putParameters(String key, Map<String, Serializable> parameters); @Override Map<String, Serializable> getParameters(String key); @Override void putBlobs(String key, List<Blob> blobs); @Override List<Blob> getBlobs(String key); @Override long getSize(String key); @Override boolean isCompleted(String key); @Override void setCompleted(String key, boolean completed); @Override void release(String key); @Override void remove(String key); static final String SEP; static final String STORAGE_SIZE; static final String DOT_COMPLETED; static final String DOT_PARAMINFO; static final String DOT_PARAM_DOT; static final String FORMAT; static final String FORMAT_JAVA; static final String DOT_BLOBLOCK; static final String DOT_BLOBINFO; static final String COUNT; static final String SIZE; static final String DOT_BLOB_DOT; static final String KEY; static final String MIMETYPE; static final String ENCODING; static final String FILENAME; static final String LENGTH; static final String DIGEST; static final String CONFIG_KEY_VALUE_STORE; static final String CONFIG_BLOB_PROVIDER; static final String CONFIG_DEFAULT_BLOB_PROVIDER; static final String CONFIG_DEFAULT_BLOB_PROVIDER_DEFAULT; }