1+ /**
2+ * Created by hideki on 2/29/16.
3+ * <p/>
4+ * Copyright (c) 2015 Couchbase, Inc All rights reserved.
5+ * <p/>
6+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7+ * except in compliance with the License. You may obtain a copy of the License at
8+ * <p/>
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ * <p/>
11+ * Unless required by applicable law or agreed to in writing, software distributed under the
12+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+ * either express or implied. See the License for the specific language governing permissions
14+ * and limitations under the License.
15+ *
16+ */
17+ package com .couchbase .lite .syncgateway ;
18+
19+ import com .couchbase .lite .LiteTestCaseWithDB ;
20+ import com .couchbase .lite .replicator .Replication ;
21+
22+ import java .util .ArrayList ;
23+ import java .util .HashMap ;
24+ import java .util .List ;
25+ import java .util .Map ;
26+ import java .util .concurrent .CountDownLatch ;
27+ import java .util .concurrent .TimeUnit ;
28+
29+ public class TenReplicationsTest extends LiteTestCaseWithDB {
30+ public static final String TAG = "TenReplicationsTest" ;
31+
32+ @ Override
33+ protected void setUp () throws Exception {
34+ super .setUp ();
35+
36+ if (!syncgatewayTestsEnabled ()) {
37+ return ;
38+ }
39+ }
40+
41+ public void testStopAllReplsAndDeleteDB () throws Exception {
42+ if (!syncgatewayTestsEnabled ()) {
43+ return ;
44+ }
45+
46+ // create 10 repls with different filter and wait till all becomes idle state
47+ final int NUM_REPLS = 10 ;
48+ List <Replication > repls = new ArrayList <Replication >(NUM_REPLS );
49+ for (int i = 0 ; i < NUM_REPLS ; i ++) {
50+ Replication repl ;
51+ if (i % 2 == 0 )
52+ repl = database .createPushReplication (getReplicationURL ());
53+ else
54+ repl = database .createPullReplication (getReplicationURL ());
55+ repl .setContinuous (true );
56+
57+ repl .setFilter ("foo/bar" + i );
58+ Map <String , Object > params = new HashMap <String , Object >();
59+ params .put ("value" , i );
60+ repl .setFilterParams (params );
61+
62+ final CountDownLatch idle = new CountDownLatch (1 );
63+ repl .addChangeListener (new ReplicationIdleObserver (idle ));
64+ repl .start ();
65+ assertTrue (idle .await (10 , TimeUnit .SECONDS ));
66+ }
67+
68+ // make sure if 10 repls are active
69+ assertEquals (NUM_REPLS , database .getActiveReplications ().size ());
70+
71+ // stop all repls by repl.stop()
72+ for (final Replication repl : repls )
73+ repl .stop ();
74+ // delete db and measure elapsed time
75+ long start = System .currentTimeMillis ();
76+ database .delete ();
77+ assertTrue ((System .currentTimeMillis () - start ) / 1000 < 30 );
78+ }
79+ }
0 commit comments