Database { public static native void CreateSyncgroup(String name, Id syncgroupId, SyncgroupSpec spec, SyncgroupMemberInfo info) throws VError;  static native VersionedPermissions GetPermissions(String name); static native void SetPermissions(String name, VersionedPermissions permissions); static native void Create(String name, Permissions permissions); static native void Destroy(String name); static native boolean Exists(String name); static native String BeginBatch(String name, BatchOptions options); static native List<Id> ListCollections(String name, String batchHandle); static native void Commit(String name, String batchHandle); static native void Abort(String name, String batchHandle); static native byte[] GetResumeMarker(String name, String batchHandle); static native List<Id> ListSyncgroups(String name); static native void CreateSyncgroup(String name, Id syncgroupId, SyncgroupSpec spec, SyncgroupMemberInfo info); static native SyncgroupSpec JoinSyncgroup(String name, String remoteSyncbaseName, List<String> expectedSyncbaseBlessings, Id syncgroupId, SyncgroupMemberInfo info); static native void LeaveSyncgroup(String name, Id syncgroupId); static native void DestroySyncgroup(String name, Id syncgroupId); static native void EjectFromSyncgroup(String name, Id syncgroupId, String member); static native VersionedSyncgroupSpec GetSyncgroupSpec(String name, Id syncgroupId); static native void SetSyncgroupSpec(String name, Id syncgroupId, VersionedSyncgroupSpec spec); static native Map<String, SyncgroupMemberInfo> GetSyncgroupMembers(String name, Id syncgroupId); static native void WatchPatterns(String name, byte[] resumeMarker, List<CollectionRowPattern> patterns, WatchPatternsCallbacks callbacks); static native long SyncgroupInvitesNewScan(String name, SyncgroupInvitesCallbacks callbacks); static native void SyncgroupInvitesStopScan(long id);  }
@Test public void createSyncgroup() { Id dbId = new Id("idp:a:angrybirds", "create_syncgroups"); String dbName = dbId.encode(); Id sgId = new Id("...", "syncgroup"); Id collectionId = new Id("...", "collection"); String collectionName = Util.NamingJoin(Arrays.asList(dbName, collectionId.encode())); try { Database.Create(dbName, anyDbPermissions()); String batchHandle = Database.BeginBatch(dbId.encode(), null); Collection.Create(collectionName, batchHandle, anyCollectionPermissions()); Database.Commit(dbName, batchHandle); SyncgroupSpec spec = new SyncgroupSpec(); spec.collections = singletonList(collectionId); spec.permissions = anySyncgroupPermissions(); SyncgroupMemberInfo info = new SyncgroupMemberInfo(); info.syncPriority = 1; info.blobDevType = 2; Database.CreateSyncgroup(dbName, sgId, spec, info); List<Id> syncgroups = Database.ListSyncgroups(dbName); assertEquals(1, syncgroups.size()); Id actual = syncgroups.get(0); assertEquals(sgId.blessing, actual.blessing); assertEquals(sgId.name, actual.name); VersionedSyncgroupSpec verSpec = Database.GetSyncgroupSpec(dbName, sgId); assertNotNull(verSpec.version); assertTrue(verSpec.version.length() > 0); assertNotNull(verSpec.syncgroupSpec); assertEquals(1, verSpec.syncgroupSpec.collections.size()); assertEquals( new String(spec.permissions.json), new String(verSpec.syncgroupSpec.permissions.json).trim()); actual = syncgroups.get(0); assertEquals(sgId.blessing, actual.blessing); assertEquals(sgId.name, actual.name); verSpec.syncgroupSpec.description = "Dummy description"; Database.SetSyncgroupSpec(dbName, sgId, verSpec); assertEquals(verSpec.syncgroupSpec.description, Database.GetSyncgroupSpec(dbName, sgId).syncgroupSpec.description); Map<String, SyncgroupMemberInfo> members = Database.GetSyncgroupMembers(dbName, sgId); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.keySet().iterator().next().length() > 0); assertEquals(info.syncPriority, members.values().iterator().next().syncPriority); assertEquals(info.blobDevType, members.values().iterator().next().blobDevType); } catch (VError vError) { vError.printStackTrace(); fail(vError.toString()); } }