usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/2] incubator-usergrid git commit: Fixed assetResource tests. Code written for s3 is not applicable for code written against the local system.
Date Tue, 02 Jun 2015 18:37:13 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-dev 92ecf016d -> 81b2c0406


Fixed assetResource tests. Code written for s3 is not applicable for code written against
the local system.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ec2f8834
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ec2f8834
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ec2f8834

Branch: refs/heads/two-dot-o-dev
Commit: ec2f88345944f6b486e1e4ef391e62b077e793b7
Parents: 6e1ef16
Author: GERey <greyes@apigee.com>
Authored: Tue Jun 2 11:34:59 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Tue Jun 2 11:34:59 2015 -0700

----------------------------------------------------------------------
 .../applications/assets/AssetResourceIT.java    | 22 ++---------
 .../assets/data/LocalFileBinaryStore.java       | 39 +++++++++++++++++---
 2 files changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec2f8834/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
index 6455748..45ff406 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
@@ -285,8 +285,7 @@ public class AssetResourceIT extends AbstractRestIT {
         String uuid = idNode.textValue();
 
         // get entity
-        long timeout = System.currentTimeMillis() + 60000;
-        while ( true ) {
+        //TODO: seperate tests for s3 and local system property tests.
             LOG.info( "Waiting for upload to finish..." );
             Thread.sleep( 2000 );
             node = mapper.readTree( resource().path( orgAppPath + "/foos/" + uuid )
@@ -294,14 +293,6 @@ public class AssetResourceIT extends AbstractRestIT {
                 .accept( MediaType.APPLICATION_JSON_TYPE )
                 .get( String.class ) );
 
-            // poll for the upload to complete
-            if ( node.findValue( AssetUtils.E_TAG ) != null ) {
-                break;
-            }
-            if ( System.currentTimeMillis() > timeout ) {
-                throw new TimeoutException();
-            }
-        }
         LOG.info( "Upload complete!" );
 
         // get data
@@ -351,24 +342,17 @@ public class AssetResourceIT extends AbstractRestIT {
 
             // get entity
             String errorMessage = null;
-            long timeout = System.currentTimeMillis() + 60000;
-            while (true) {
+            //TODO: seperate tests for s3 and local system property tests.
                 LOG.info( "Waiting for upload to finish..." );
                 Thread.sleep( 2000 );
                 node = resource().path( orgAppPath + "/bars/" + uuid )
                         .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON_TYPE
)
                         .get( JsonNode.class );
-                //logNode( node );
 
-                // poll for the error to happen
+                // check for the error
                 if (node.findValue( "error" ) != null) {
                     errorMessage = node.findValue("error").asText();
-                    break;
-                }
-                if (System.currentTimeMillis() > timeout) {
-                    throw new TimeoutException();
                 }
-            }
 
             assertTrue( errorMessage.startsWith("Asset size "));
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec2f8834/stack/services/src/main/java/org/apache/usergrid/services/assets/data/LocalFileBinaryStore.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/LocalFileBinaryStore.java
b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/LocalFileBinaryStore.java
index 633f452..0da74ad 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/LocalFileBinaryStore.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/LocalFileBinaryStore.java
@@ -22,9 +22,14 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Map;
+import java.util.Properties;
 import java.util.UUID;
 
+import org.springframework.beans.factory.annotation.Autowired;
+
 import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.utils.StringUtils;
 
 import org.apache.commons.io.FileUtils;
 
@@ -34,6 +39,8 @@ public class LocalFileBinaryStore implements BinaryStore {
 
     private String reposLocation = FileUtils.getTempDirectoryPath();
 
+    @Autowired
+    private Properties properties;
 
     /** Control where to store the file repository. In the system's temp dir by default.
*/
     public void setReposLocation( String reposLocation ) {
@@ -62,15 +69,37 @@ public class LocalFileBinaryStore implements BinaryStore {
 
         FileUtils.copyInputStreamToFile( inputStream, file );
 
+        long maxSizeBytes = 50 * FileUtils.ONE_MB;
         long size = FileUtils.sizeOf( file );
 
+        String maxSizeMbString = properties.getProperty( "usergrid.binary.max-size-mb", "50"
);
         Map<String, Object> fileMetadata = AssetUtils.getFileMetadata( entity );
-        fileMetadata.put( AssetUtils.CONTENT_LENGTH, size );
-        fileMetadata.put( AssetUtils.LAST_MODIFIED, System.currentTimeMillis() );
 
-        // if we were successful, write the mime type
-        if ( file.exists() ) {
-            AssetMimeHandler.get().getMimeType( entity, file );
+
+        if ( StringUtils.isNumeric( maxSizeMbString )) {
+            maxSizeBytes = Long.parseLong( maxSizeMbString ) * FileUtils.ONE_MB;
+        }
+
+        if ( size > maxSizeBytes ) {
+            try {
+                fileMetadata.put( "error", "Asset size " + file.length()
+                    + " is larger than max size of " + maxSizeBytes );
+                //em.update( entity );
+                //tempFile.delete();
+
+            } catch ( Exception e ) {
+                //LOG.error( "Error updating entity with error message", e);
+            }
+
+        }
+        else {
+            fileMetadata.put( AssetUtils.CONTENT_LENGTH, size );
+            fileMetadata.put( AssetUtils.LAST_MODIFIED, System.currentTimeMillis() );
+
+            // if we were successful, write the mime type
+            if ( file.exists() ) {
+                AssetMimeHandler.get().getMimeType( entity, file );
+            }
         }
     }
 


Mime
View raw message