@Test public void verifyMaxSizeException() throws Exception { byte[] bytes = new byte[1024 * 1024 + 1]; Blob blob = Blobs.createBlob(bytes); ts.putBlobs("foo", Collections.singletonList(blob)); try { ts.putBlobs("bar", Collections.singletonList(Blobs.createBlob("x"))); fail("Should have exceeded maximum transient space"); } catch (MaximumTransientSpaceExceeded e) { assertEquals("Maximum Transient Space Exceeded", e.getMessage()); } }
@Override public void putBlobs(String key, List<Blob> blobs) { if (absoluteMaxSize > 0 && getStorageSize() > absoluteMaxSize) { doGC(); if (getStorageSize() > absoluteMaxSize) { throw new MaximumTransientSpaceExceeded(); } } BlobProvider bp = getBlobProvider(); long totalSize = 0; List<String> blobMapJsons = new ArrayList<>(); for (Blob blob : blobs) { long size = blob.getLength(); if (size >= 0) { totalSize += size; } String blobKey; try { blobKey = bp.writeBlob(blob); } catch (IOException e) { throw new NuxeoException(e); } Map<String, String> blobMap = new HashMap<>(); blobMap.put(KEY, blobKey); blobMap.put(MIMETYPE, blob.getMimeType()); blobMap.put(ENCODING, blob.getEncoding()); blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); String blobMapJson = toJson(blobMap); blobMapJsons.add(blobMapJson); } Map<String, String> blobInfoMap = new HashMap<>(); blobInfoMap.put(COUNT, String.valueOf(blobs.size())); blobInfoMap.put(SIZE, String.valueOf(totalSize)); String blobInfoMapJson = toJson(blobInfoMap); KeyValueStore kvs = getKeyValueStore(); acquireBlobLockOrThrow(key, kvs); try { removeBlobs(key, kvs); int i = 0; for (String blobMapJson : blobMapJsons) { kvs.put(key + DOT_BLOB_DOT + i, blobMapJson, ttl); i++; } kvs.put(key + DOT_BLOBINFO, blobInfoMapJson, ttl); addStorageSize(totalSize, kvs); markEntryExists(key, kvs); } finally { releaseBlobLock(key, kvs); } }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public void putBlobs(String key, List<Blob> blobs) { if (absoluteMaxSize > 0 && getStorageSize() > absoluteMaxSize) { doGC(); if (getStorageSize() > absoluteMaxSize) { throw new MaximumTransientSpaceExceeded(); } } BlobProvider bp = getBlobProvider(); long totalSize = 0; List<String> blobMapJsons = new ArrayList<>(); for (Blob blob : blobs) { long size = blob.getLength(); if (size >= 0) { totalSize += size; } String blobKey; try { blobKey = bp.writeBlob(blob); } catch (IOException e) { throw new NuxeoException(e); } Map<String, String> blobMap = new HashMap<>(); blobMap.put(KEY, blobKey); blobMap.put(MIMETYPE, blob.getMimeType()); blobMap.put(ENCODING, blob.getEncoding()); blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); String blobMapJson = toJson(blobMap); blobMapJsons.add(blobMapJson); } Map<String, String> blobInfoMap = new HashMap<>(); blobInfoMap.put(COUNT, String.valueOf(blobs.size())); blobInfoMap.put(SIZE, String.valueOf(totalSize)); String blobInfoMapJson = toJson(blobInfoMap); KeyValueStore kvs = getKeyValueStore(); acquireBlobLockOrThrow(key, kvs); try { removeBlobs(key, kvs); int i = 0; for (String blobMapJson : blobMapJsons) { kvs.put(key + DOT_BLOB_DOT + i, blobMapJson, ttl); i++; } kvs.put(key + DOT_BLOBINFO, blobInfoMapJson, ttl); addStorageSize(totalSize, kvs); markEntryExists(key, kvs); } finally { releaseBlobLock(key, kvs); } } }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public void putBlobs(String key, List<Blob> blobs) { if (absoluteMaxSize > 0 && getStorageSize() > absoluteMaxSize) { doGC(); if (getStorageSize() > absoluteMaxSize) { throw new MaximumTransientSpaceExceeded(); } } BlobProvider bp = getBlobProvider(); long totalSize = 0; List<String> blobMapJsons = new ArrayList<>(); for (Blob blob : blobs) { long size = blob.getLength(); if (size >= 0) { totalSize += size; } String blobKey; try { blobKey = bp.writeBlob(blob); } catch (IOException e) { throw new NuxeoException(e); } Map<String, String> blobMap = new HashMap<>(); blobMap.put(KEY, blobKey); blobMap.put(MIMETYPE, blob.getMimeType()); blobMap.put(ENCODING, blob.getEncoding()); blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); String blobMapJson = toJson(blobMap); blobMapJsons.add(blobMapJson); } Map<String, String> blobInfoMap = new HashMap<>(); blobInfoMap.put(COUNT, String.valueOf(blobs.size())); blobInfoMap.put(SIZE, String.valueOf(totalSize)); String blobInfoMapJson = toJson(blobInfoMap); KeyValueStore kvs = getKeyValueStore(); acquireBlobLockOrThrow(key, kvs); try { removeBlobs(key, kvs); int i = 0; for (String blobMapJson : blobMapJsons) { kvs.put(key + DOT_BLOB_DOT + i, blobMapJson, ttl); i++; } kvs.put(key + DOT_BLOBINFO, blobInfoMapJson, ttl); addStorageSize(totalSize, kvs); markEntryExists(key, kvs); } finally { releaseBlobLock(key, kvs); } }  }
KeyValueBlobTransientStore implements TransientStoreProvider { @Override public void putBlobs(String key, List<Blob> blobs) { if (absoluteMaxSize > 0 && getStorageSize() > absoluteMaxSize) { doGC(); if (getStorageSize() > absoluteMaxSize) { throw new MaximumTransientSpaceExceeded(); } } BlobProvider bp = getBlobProvider(); long totalSize = 0; List<String> blobMapJsons = new ArrayList<>(); for (Blob blob : blobs) { long size = blob.getLength(); if (size >= 0) { totalSize += size; } String blobKey; try { blobKey = bp.writeBlob(blob); } catch (IOException e) { throw new NuxeoException(e); } Map<String, String> blobMap = new HashMap<>(); blobMap.put(KEY, blobKey); blobMap.put(MIMETYPE, blob.getMimeType()); blobMap.put(ENCODING, blob.getEncoding()); blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); String blobMapJson = toJson(blobMap); blobMapJsons.add(blobMapJson); } Map<String, String> blobInfoMap = new HashMap<>(); blobInfoMap.put(COUNT, String.valueOf(blobs.size())); blobInfoMap.put(SIZE, String.valueOf(totalSize)); String blobInfoMapJson = toJson(blobInfoMap); KeyValueStore kvs = getKeyValueStore(); acquireBlobLockOrThrow(key, kvs); try { removeBlobs(key, kvs); int i = 0; for (String blobMapJson : blobMapJsons) { kvs.put(key + DOT_BLOB_DOT + i, blobMapJson, ttl); i++; } kvs.put(key + DOT_BLOBINFO, blobInfoMapJson, ttl); addStorageSize(totalSize, kvs); markEntryExists(key, kvs); } finally { releaseBlobLock(key, kvs); } }  @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 void putBlobs(String key, List<Blob> blobs) { if (absoluteMaxSize > 0 && getStorageSize() > absoluteMaxSize) { doGC(); if (getStorageSize() > absoluteMaxSize) { throw new MaximumTransientSpaceExceeded(); } } BlobProvider bp = getBlobProvider(); long totalSize = 0; List<String> blobMapJsons = new ArrayList<>(); for (Blob blob : blobs) { long size = blob.getLength(); if (size >= 0) { totalSize += size; } String blobKey; try { blobKey = bp.writeBlob(blob); } catch (IOException e) { throw new NuxeoException(e); } Map<String, String> blobMap = new HashMap<>(); blobMap.put(KEY, blobKey); blobMap.put(MIMETYPE, blob.getMimeType()); blobMap.put(ENCODING, blob.getEncoding()); blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); String blobMapJson = toJson(blobMap); blobMapJsons.add(blobMapJson); } Map<String, String> blobInfoMap = new HashMap<>(); blobInfoMap.put(COUNT, String.valueOf(blobs.size())); blobInfoMap.put(SIZE, String.valueOf(totalSize)); String blobInfoMapJson = toJson(blobInfoMap); KeyValueStore kvs = getKeyValueStore(); acquireBlobLockOrThrow(key, kvs); try { removeBlobs(key, kvs); int i = 0; for (String blobMapJson : blobMapJsons) { kvs.put(key + DOT_BLOB_DOT + i, blobMapJson, ttl); i++; } kvs.put(key + DOT_BLOBINFO, blobInfoMapJson, ttl); addStorageSize(totalSize, kvs); markEntryExists(key, kvs); } finally { releaseBlobLock(key, kvs); } }  @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; }