TBR: website: Tests for Syncing Data Guide code snippets
Fixing Batching code snippts ( Tests to come soon )
Change-Id: Id5fb9d929bcae486c828544b32ed389ef4158c64
diff --git a/Makefile b/Makefile
index 9a28af5..2901a8c 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,7 @@
syncbaseAndroidFirstApp = syncbase/first-app
syncbaseAndroidDataModel = syncbase/guides/data-model
syncbaseAndroidDataFlow = syncbase/guides/data-flow
+syncbaseAndroidDataSync = syncbase/guides/synchronization
# Scripts that 'complete' the named tutorials, creating all relevant files
# (code, credentials, etc.) but skipping ephemeral steps like starting servers,
@@ -388,7 +389,8 @@
content/$(syncbaseAndroidQuickstart).md \
content/$(syncbaseAndroidFirstApp).md \
content/$(syncbaseAndroidDataModel).md \
- content/$(syncbaseAndroidDataFlow).md
+ content/$(syncbaseAndroidDataFlow).md \
+ content/$(syncbaseAndroidDataSync).md
.PHONY: test
test: test-site test-tutorials-core test-tutorials-java test-syncbase-android
@@ -420,7 +422,7 @@
# Test Syncbase quickstart, guides and tutorials for Android.
# Called from v.io/x/devtools/jiri-test/internal/test/website.go.
test-syncbase-android: build
- $(MDRIP) --blockTimeOut 10m --subshell test $(depsOneBigSyncbaseAndroidTest)
+ $(MDRIP) --blockTimeOut 15m --subshell test $(depsOneBigSyncbaseAndroidTest)
# Test tutorials against fresh external install.
#
diff --git a/content/syncbase/guides/batches.md b/content/syncbase/guides/batches.md
index 0ee4414..5beaf2b 100644
--- a/content/syncbase/guides/batches.md
+++ b/content/syncbase/guides/batches.md
@@ -63,17 +63,17 @@
```Java
db.runInBatch(new Database.BatchOperation() {
- @Override
- public void run(BatchDatabase batchDb) {
- Collection c1 = batchDb.collection("collection1");
- Collection c2 = batchDb.collection("collection2");
+ @Override
+ public void run(BatchDatabase batchDb) {
+ Collection c1 = batchDb.collection("collection1");
+ Collection c2 = batchDb.collection("collection2");
- c1.put("myKey", "myValue");
- c2.put("myKey", "myValue");
+ c1.put("myKey", "myValue");
+ c2.put("myKey", "myValue");
- // No need to commit. RunInBatch will commit and retry if necessary.
- }
-});
+ // No need to commit. RunInBatch will commit and retry if necessary.
+ }
+}, new Database.BatchOptions());
```
{{# helpers.warning }}
@@ -88,7 +88,7 @@
```Java
// WRONG: c1 is NOT part of the batch.
-Collection c1 = db.collection("collection1");
+final Collection c1 = db.collection("collection1");
{{# helpers.codedim }}
db.runInBatch(new Database.BatchOperation() {
@Override
@@ -103,7 +103,7 @@
{{# helpers.codedim }}
// No need to commit. RunInBatch will commit and retry if necessary.
}
-});
+}, new Database.BatchOptions());
{{/ helpers.codedim }}
```
@@ -113,7 +113,7 @@
to the developers to manage themselves.
```Java
-BatchDatabase batchDb = db.beginBatch();
+BatchDatabase batchDb = db.beginBatch(new Database.BatchOptions());
Collection c1 = batchDb.collection("collection1");
Collection c2 = batchDb.collection("collection2");
@@ -122,7 +122,6 @@
c2.put("myKey", "myValue");
batchDb.commit();
-
```
{{# helpers.warning }}
@@ -137,7 +136,7 @@
// WRONG: c1 is NOT part of the batch.
Collection c1 = db.collection("collection1");
{{# helpers.codedim }}
-BatchDatabase batchDb = db.beginBatch();
+BatchDatabase batchDb = db.beginBatch(new Database.BatchOptions());
// c2 is part of the batch.
Collection c2 = batchDb.collection("collection2");
diff --git a/content/syncbase/guides/synchronization.md b/content/syncbase/guides/synchronization.md
index 4a05c24..779dcf3 100644
--- a/content/syncbase/guides/synchronization.md
+++ b/content/syncbase/guides/synchronization.md
@@ -5,6 +5,29 @@
toc: true
= yaml =
+{{# helpers.hidden }}
+<!-- @setupEnvironment @test -->
+```
+export PROJECT_DIR=$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")
+cp -r $JIRI_ROOT/website/tools/android_project_stubs/example/* $PROJECT_DIR
+cat - <<EOF >> $PROJECT_DIR/app/build.gradle
+dependencies {
+ compile 'io.v:syncbase:0.1.4'
+}
+EOF
+cat - <<EOF > $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
+package io.v.syncbase.example;
+import io.v.syncbase.*;
+import java.util.Iterator;
+public class DataSync {
+ Database db;
+ User userToInvite;
+ User userToRemove;
+ void main() {
+EOF
+```
+{{/ helpers.hidden }}
+
# Introduction
Syncbase's sync protocol is peer-to-peer whereas most other sync systems require
@@ -53,23 +76,32 @@
On the inviter side, we just need to invite a user to join the collection's
syncgroup:
+<!-- @inviteUser @test -->
```
+cat - <<EOF >> $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
Collection collectionToShare = db.collection("myCollection");
-User userToInvite = new User("<email-address>");
-
-collectionToShare.getSyncgroup().inviteUser(userToInvite, AccessLevel.READ);
+collectionToShare.getSyncgroup().inviteUser(userToInvite, AccessList.AccessLevel.READ);
+EOF
```
On the invitee side, we need to handle invite requests by registering a handler:
+<!-- @addInviteHandler @test -->
```
+cat - <<EOF >> $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
db.addSyncgroupInviteHandler(new Database.SyncgroupInviteHandler() {
- @Override
- public void onInvite(SyncgroupInvite invite) {
- // Prompt the user if desired then accept or reject the invite.
- db.acceptSyncgroupInvite(invite);
- }
-});
+ @Override
+ public void onInvite(SyncgroupInvite invite) {
+ // Prompt the user if desired then accept or reject the invite.
+ db.acceptSyncgroupInvite(invite, new Database.AcceptSyncgroupInviteCallback() {
+ @Override
+ public void onSuccess(Syncgroup sg) {
+ // Accepting invitation was successful.
+ }
+ });
+ }
+}, new Database.AddSyncgroupInviteHandlerOptions());
+EOF
```
{{# helpers.info }}
@@ -91,12 +123,13 @@
disappear. Otherwise, the shared collection on target user's database will
become read-only and will no longer sync and receive updates.
+<!-- @unshareCollection @test -->
```
+cat - <<EOF >> $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
Collection sharedCollection = db.collection("myCollection");
-User userToRemove = new User("<email-address>");
-
sharedCollection.getSyncgroup().ejectUser(userToRemove);
+EOF
```
## Updating Access Level
@@ -109,11 +142,14 @@
`db.getSyncgroups()` can be used to list all syncgroups. This list includes
pre-created syncgroups for collections and other syncgroups created or joined.
+<!-- @getAllSyncgroups @test -->
```Java
+cat - <<EOF >> $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
Iterator<Syncgroup> allSyncgroups = db.getSyncgroups();
while(allSyncgroups.hasNext()) {
Syncgroup sg = allSyncgroups.next();
}
+EOF
```
# Summary
@@ -125,4 +161,15 @@
syncgroup.
* Access-level can be one of read-only, read-write, or read-write-admin.
-[Data Flow]: /syncbase/guides/data-flow.html
\ No newline at end of file
+[Data Flow]: /syncbase/guides/data-flow.html
+
+{{# helpers.hidden }}
+<!-- @compileSnippets_mayTakeMinutes @test -->
+```
+cat - <<EOF >> $PROJECT_DIR/app/src/main/java/io/v/syncbase/example/DataSync.java
+ }
+}
+EOF
+cd $PROJECT_DIR && ./gradlew assembleRelease
+```
+{{/ helpers.hidden }}
\ No newline at end of file