Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
f4daed73
Commit
f4daed73
authored
Dec 27, 2011
by
Mark Friedman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store .blk files in Blobstore
parent
c9889701
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
9 deletions
+57
-9
appinventor/appengine/src/com/google/appinventor/server/storage/ObjectifyStorageIo.java
...google/appinventor/server/storage/ObjectifyStorageIo.java
+7
-2
appinventor/appengine/tests/com/google/appinventor/server/storage/ObjectifyStorageIoTest.java
...le/appinventor/server/storage/ObjectifyStorageIoTest.java
+50
-7
No files found.
appinventor/appengine/src/com/google/appinventor/server/storage/ObjectifyStorageIo.java
View file @
f4daed73
...
@@ -922,6 +922,8 @@ public class ObjectifyStorageIo implements StorageIo {
...
@@ -922,6 +922,8 @@ public class ObjectifyStorageIo implements StorageIo {
if
(
useBlobstore
)
{
if
(
useBlobstore
)
{
fd
.
isBlob
=
true
;
fd
.
isBlob
=
true
;
fd
.
blobstorePath
=
uploadToBlobstore
(
content
);
fd
.
blobstorePath
=
uploadToBlobstore
(
content
);
// If the content was previously stored in the datastore, clear it out.
fd
.
content
=
null
;
}
else
{
}
else
{
fd
.
content
=
content
;
fd
.
content
=
content
;
}
}
...
@@ -984,8 +986,11 @@ public class ObjectifyStorageIo implements StorageIo {
...
@@ -984,8 +986,11 @@ public class ObjectifyStorageIo implements StorageIo {
return
blobstoreFile
.
getFullPath
();
return
blobstoreFile
.
getFullPath
();
}
}
private
boolean
useBlobstoreForFile
(
String
fileName
)
{
@VisibleForTesting
return
fileName
.
contains
(
"assets/"
)
||
fileName
.
endsWith
(
".apk"
);
boolean
useBlobstoreForFile
(
String
fileName
)
{
return
fileName
.
contains
(
"assets/"
)
||
fileName
.
endsWith
(
".apk"
)
||
(
fileName
.
contains
(
"src/"
)
&&
fileName
.
endsWith
(
".blk"
));
}
}
@Override
@Override
...
...
appinventor/appengine/tests/com/google/appinventor/server/storage/ObjectifyStorageIoTest.java
View file @
f4daed73
...
@@ -16,7 +16,7 @@ import java.io.UnsupportedEncodingException;
...
@@ -16,7 +16,7 @@ import java.io.UnsupportedEncodingException;
import
java.util.Arrays
;
import
java.util.Arrays
;
/**
/**
* Tests for {@link Objectify
storage
}.
* Tests for {@link Objectify
StorageIo
}.
*
*
* @author sharon@google.com (Sharon Perl)
* @author sharon@google.com (Sharon Perl)
*/
*/
...
@@ -44,6 +44,8 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
...
@@ -44,6 +44,8 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
private
static
final
byte
[]
ASSET_FILE_CONTENT1
=
{
(
byte
)
0
,
(
byte
)
1
,
(
byte
)
32
,
(
byte
)
255
};
private
static
final
byte
[]
ASSET_FILE_CONTENT1
=
{
(
byte
)
0
,
(
byte
)
1
,
(
byte
)
32
,
(
byte
)
255
};
private
static
final
String
APK_FILE_NAME1
=
"/ode/build/Android/HelloPurr.apk"
;
private
static
final
String
APK_FILE_NAME1
=
"/ode/build/Android/HelloPurr.apk"
;
private
static
final
byte
[]
APK_FILE_CONTENT
=
{
(
byte
)
0
,
(
byte
)
1
,
(
byte
)
32
,
(
byte
)
255
};
private
static
final
byte
[]
APK_FILE_CONTENT
=
{
(
byte
)
0
,
(
byte
)
1
,
(
byte
)
32
,
(
byte
)
255
};
private
static
final
String
BLOCK_FILE_NAME
=
"src/blocks.blk"
;
private
static
final
byte
[]
BLOCK_FILE_CONTENT
=
{(
byte
)
0
,
(
byte
)
1
,
(
byte
)
32
,
(
byte
)
255
};
private
ObjectifyStorageIo
storage
;
private
ObjectifyStorageIo
storage
;
private
Project
project
;
private
Project
project
;
...
@@ -382,28 +384,64 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
...
@@ -382,28 +384,64 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
FORM_QUALIFIED_NAME
);
FORM_QUALIFIED_NAME
);
storage
.
addSourceFilesToProject
(
USER_ID
,
projectId
,
false
,
ASSET_FILE_NAME1
);
storage
.
addSourceFilesToProject
(
USER_ID
,
projectId
,
false
,
ASSET_FILE_NAME1
);
storage
.
uploadRawFile
(
projectId
,
ASSET_FILE_NAME1
,
USER_ID
,
ASSET_FILE_CONTENT1
);
storage
.
uploadRawFile
(
projectId
,
ASSET_FILE_NAME1
,
USER_ID
,
ASSET_FILE_CONTENT1
);
storage
.
addSourceFilesToProject
(
USER_ID
,
projectId
,
false
,
BLOCK_FILE_NAME
);
storage
.
uploadRawFile
(
projectId
,
BLOCK_FILE_NAME
,
USER_ID
,
BLOCK_FILE_CONTENT
);
storage
.
addOutputFilesToProject
(
USER_ID
,
projectId
,
APK_FILE_NAME1
);
storage
.
addOutputFilesToProject
(
USER_ID
,
projectId
,
APK_FILE_NAME1
);
storage
.
uploadRawFile
(
projectId
,
APK_FILE_NAME1
,
USER_ID
,
APK_FILE_CONTENT
);
storage
.
uploadRawFile
(
projectId
,
APK_FILE_NAME1
,
USER_ID
,
APK_FILE_CONTENT
);
assertTrue
(
storage
.
getProjectSourceFiles
(
USER_ID
,
projectId
).
contains
(
ASSET_FILE_NAME1
));
assertTrue
(
storage
.
getProjectSourceFiles
(
USER_ID
,
projectId
).
contains
(
ASSET_FILE_NAME1
));
assertTrue
(
storage
.
getProjectOutputFiles
(
USER_ID
,
projectId
).
contains
(
APK_FILE_NAME1
));
assertTrue
(
storage
.
getProjectOutputFiles
(
USER_ID
,
projectId
).
contains
(
APK_FILE_NAME1
));
assertTrue
(
java
.
util
.
Arrays
.
equals
(
ASSET_FILE_CONTENT1
,
assertTrue
(
Arrays
.
equals
(
ASSET_FILE_CONTENT1
,
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
ASSET_FILE_NAME1
)));
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
ASSET_FILE_NAME1
)));
assertTrue
(
java
.
util
.
Arrays
.
equals
(
APK_FILE_CONTENT
,
assertTrue
(
Arrays
.
equals
(
APK_FILE_CONTENT
,
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
APK_FILE_NAME1
)));
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
APK_FILE_NAME1
)));
ObjectifyStorageIo
objstorage
=
(
ObjectifyStorageIo
)
storage
;
assertTrue
(
Arrays
.
equals
(
BLOCK_FILE_CONTENT
,
assertTrue
(
objstorage
.
isBlobFile
(
projectId
,
ASSET_FILE_NAME1
));
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
BLOCK_FILE_NAME
)));
assertTrue
(
objstorage
.
isBlobFile
(
projectId
,
APK_FILE_NAME1
));
assertTrue
(
storage
.
isBlobFile
(
projectId
,
ASSET_FILE_NAME1
));
assertTrue
(
storage
.
isBlobFile
(
projectId
,
APK_FILE_NAME1
));
assertTrue
(
storage
.
isBlobFile
(
projectId
,
BLOCK_FILE_NAME
));
storage
.
removeSourceFilesFromProject
(
USER_ID
,
projectId
,
false
,
ASSET_FILE_NAME1
);
storage
.
removeSourceFilesFromProject
(
USER_ID
,
projectId
,
false
,
ASSET_FILE_NAME1
);
storage
.
removeOutputFilesFromProject
(
USER_ID
,
projectId
,
APK_FILE_NAME1
);
storage
.
removeOutputFilesFromProject
(
USER_ID
,
projectId
,
APK_FILE_NAME1
);
storage
.
removeSourceFilesFromProject
(
USER_ID
,
projectId
,
false
,
BLOCK_FILE_NAME
);
assertFalse
(
storage
.
getProjectSourceFiles
(
USER_ID
,
projectId
).
contains
(
ASSET_FILE_NAME1
));
assertFalse
(
storage
.
getProjectSourceFiles
(
USER_ID
,
projectId
).
contains
(
ASSET_FILE_NAME1
));
assertFalse
(
storage
.
getProjectOutputFiles
(
USER_ID
,
projectId
).
contains
(
APK_FILE_NAME1
));
assertFalse
(
storage
.
getProjectOutputFiles
(
USER_ID
,
projectId
).
contains
(
APK_FILE_NAME1
));
assertFalse
(
storage
.
getProjectOutputFiles
(
USER_ID
,
projectId
).
contains
(
BLOCK_FILE_NAME
));
// TODO(sharon): would be good to check that blobrefs are deleted from blobstore too
// TODO(sharon): would be good to check that blobrefs are deleted from blobstore too
// TODO(sharon): should test large blob files (e.g., >2MB (chunk size), >4MB (row size));
// TODO(sharon): should test large blob files (e.g., >2MB (chunk size), >4MB (row size));
}
}
public
void
testOldBlockFilesInDatastoreStillWork
()
{
// Create new storage object that forces storage in the datastore
ObjectifyStorageIo
oldStyleStorage
=
new
ObjectifyStorageIo
()
{
@Override
boolean
useBlobstoreForFile
(
String
fileName
)
{
return
false
;
}
};
final
String
USER_ID
=
"1310"
;
oldStyleStorage
.
getUser
(
USER_ID
);
long
projectId
=
createProject
(
USER_ID
,
PROJECT_NAME
,
YoungAndroidProjectNode
.
YOUNG_ANDROID_PROJECT_TYPE
,
FORM_QUALIFIED_NAME
);
oldStyleStorage
.
addSourceFilesToProject
(
USER_ID
,
projectId
,
false
,
BLOCK_FILE_NAME
);
oldStyleStorage
.
uploadRawFile
(
projectId
,
BLOCK_FILE_NAME
,
USER_ID
,
BLOCK_FILE_CONTENT
);
assertTrue
(
Arrays
.
equals
(
BLOCK_FILE_CONTENT
,
oldStyleStorage
.
downloadRawFile
(
USER_ID
,
projectId
,
BLOCK_FILE_NAME
)));
assertFalse
(
oldStyleStorage
.
isBlobFile
(
projectId
,
BLOCK_FILE_NAME
));
// Test that we can still get the content with an ordinary storage object
assertTrue
(
Arrays
.
equals
(
BLOCK_FILE_CONTENT
,
storage
.
downloadRawFile
(
USER_ID
,
projectId
,
BLOCK_FILE_NAME
)));
// Test that ordinary storage objects will still store the data in blobstore
storage
.
uploadRawFile
(
projectId
,
BLOCK_FILE_NAME
,
USER_ID
,
BLOCK_FILE_CONTENT
);
assertTrue
(
storage
.
isBlobFile
(
projectId
,
BLOCK_FILE_NAME
));
}
public
void
testGetProject
()
{
public
void
testGetProject
()
{
final
String
USER_ID
=
"1400"
;
final
String
USER_ID
=
"1400"
;
storage
.
getUser
(
USER_ID
);
storage
.
getUser
(
USER_ID
);
...
@@ -463,9 +501,14 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
...
@@ -463,9 +501,14 @@ public class ObjectifyStorageIoTest extends LocalDatastoreTestCase {
}
}
private
long
createProject
(
String
userId
,
String
name
,
String
type
,
String
fileName
)
{
private
long
createProject
(
String
userId
,
String
name
,
String
type
,
String
fileName
)
{
return
createProject
(
userId
,
name
,
type
,
fileName
,
storage
);
}
private
long
createProject
(
String
userId
,
String
name
,
String
type
,
String
fileName
,
ObjectifyStorageIo
storageIo
)
{
Project
project
=
new
Project
(
name
);
Project
project
=
new
Project
(
name
);
project
.
setProjectType
(
type
);
project
.
setProjectType
(
type
);
project
.
addTextFile
(
new
TextFile
(
fileName
,
""
));
project
.
addTextFile
(
new
TextFile
(
fileName
,
""
));
return
storage
.
createProject
(
userId
,
project
,
SETTINGS
);
return
storage
Io
.
createProject
(
userId
,
project
,
SETTINGS
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment