title: Couchbase Lite pull replication fails with error in a sample Couchbase Mobile End to End testing project
body: <p>I am getting started with Couchbase Mobile. The feature that I am most interested (for now) is <code>PULL</code> replication (keep data on mobile in sync with backend database). </p>
  
  <p>I followed the steps described in <a href="https://blog.couchbase.com/using-docker-with-couchbase-mobile/" rel="noreferrer">Using Docker to develop with Couchbase Mobile</a> and have got the Couchbase server (enterprise-6.5.0) and sync gateway (2.7.0-enterprise) deployed locally. I have added the <code>beer-sample</code> database (has ~8400 documents) and now I'm trying to replicate it on an android application. I customized the <a href="https://github.com/couchbaselabs/userprofile-couchbase-mobile-android" rel="noreferrer">Userprofile Couchbase Mobile Android</a> project and I pointed it to my local sync-gateway. I have a piece of code to replicate like below :</p>
  
  <pre><code>  public static void startPullReplication() {
      Log.i("Pull", "Start pull beer-sample");
      URI url = null;
      try {
        url = new URI(String.format("%s/%s", "ws://10.0.1.7:4984", beerSampleDbName));
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
  
      ReplicatorConfiguration config =
          new ReplicatorConfiguration(beerSampleDatabase, new URLEndpoint(url)); // &lt;1&gt;
      config.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL); // &lt;2&gt;
      config.setContinuous(true); // &lt;3&gt;
      config.setAuthenticator(new BasicAuthenticator("admin", "password")); // &lt;4&gt;
      //    config.setChannels(Arrays.asList("channel." + "admin")); // &lt;5&gt;
  
      replicator = new Replicator(config);
      replicatorListenerToken =
          replicator.addChangeListener(
              new ReplicatorChangeListener() {
                @Override
                public void changed(ReplicatorChange change) {
                  Log.i("Pull", "Changed pull beer sample : " + change.getStatus());
                  if (change
                      .getReplicator()
                      .getStatus()
                      .getActivityLevel()
                      .equals(Replicator.ActivityLevel.IDLE)) {
                    Log.i("Replication Comp Log", "Scheduler Completed");
                  }
                  if (change
                          .getReplicator()
                          .getStatus()
                          .getActivityLevel()
                          .equals(Replicator.ActivityLevel.STOPPED)
                      || change
                          .getReplicator()
                          .getStatus()
                          .getActivityLevel()
                          .equals(Replicator.ActivityLevel.OFFLINE)) {
                    Log.i("Rep Scheduler  Log", "ReplicationTag Stopped");
                  }
                }
              });
      replicator.start();
  
      Log.i("Pull", "Replication beer-sample started");
    }
  </code></pre>
  
  <p>and listen to changes in the db like below :</p>
  
  <pre><code>
    private void registerForDatabaseChanges() {
      beerSampleListenerToken =
          beerSampleDatabase.addChangeListener(
              new DatabaseChangeListener() {
                Integer i=0;
                @Override
                public void changed(@NonNull DatabaseChange change) {
                  Log.i("DatabaseChangeEvent", String.valueOf(i));
                  i++;
                  for (String docId : change.getDocumentIDs()) {
                    Document doc = beerSampleDatabase.getDocument(docId);
                    if (doc != null) {
                      Log.i("DatabaseChangeEvent", doc.getId() + ": Document was added/updated");
                    } else {
                      Log.i("DatabaseChangeEvent", docId + "Document was deleted");
                    }
                  }
                }
              });
    }
  
  </code></pre>
  
  <p>Now when I run the app I am getting the following logs.</p>
  
  <pre><code>2020-02-11 15:44:46.420 22513-22513/com.cbmob.testapp W/CouchbaseLite/DATABASE: Database.log.getFile().getConfig() is null, meaning file logging is disabled.  Log files required for product support are not being generated.
  2020-02-11 15:44:46.615 22513-22545/com.cbmob.testapp D/OpenGLRenderer: HWUI GL Pipeline
  2020-02-11 15:44:46.744 22513-22545/com.cbmob.testapp I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
  2020-02-11 15:44:46.744 22513-22545/com.cbmob.testapp I/OpenGLRenderer: Initialized EGL, version 1.4
  2020-02-11 15:44:46.744 22513-22545/com.cbmob.testapp D/OpenGLRenderer: Swap behavior 1
  2020-02-11 15:44:46.745 22513-22545/com.cbmob.testapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
  2020-02-11 15:44:46.745 22513-22545/com.cbmob.testapp D/OpenGLRenderer: Swap behavior 0
  2020-02-11 15:44:46.752 22513-22545/com.cbmob.testapp D/EGL_emulation: eglCreateContext: 0xa9f30d40: maj 3 min 0 rcv 3
  2020-02-11 15:44:46.765 22513-22545/com.cbmob.testapp D/EGL_emulation: eglMakeCurrent: 0xa9f30d40: ver 3 0 (tinfo 0x9f7bf880)
  2020-02-11 15:44:46.976 22513-22545/com.cbmob.testapp D/EGL_emulation: eglMakeCurrent: 0xa9f30d40: ver 3 0 (tinfo 0x9f7bf880)
  
  
  
  2020-02-11 15:44:56.458 22513-22513/com.cbmob.testapp I/Pull: Start pull beer-sample
  2020-02-11 15:44:56.480 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.open() socket -&gt; 2852069288
  2020-02-11 15:44:56.480 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.open() clazz -&gt; com.couchbase.lite.internal.replicator.CBLWebSocket
  2020-02-11 15:44:56.482 22513-22513/com.cbmob.testapp I/Pull: Replication beer-sample started
  2020-02-11 15:44:56.497 22513-22513/com.cbmob.testapp I/Pull: Changed pull beer sample : Status{activityLevel=CONNECTING, progress=Progress{completed=0, total=0}, error=null}
  2020-02-11 15:44:56.519 22513-22576/com.cbmob.testapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
  2020-02-11 15:44:56.528 22513-22576/com.cbmob.testapp E/CouchbaseLite/NETWORK: CBLWebSocket.socket_open()
  2020-02-11 15:44:56.582 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.write() handle -&gt; 2852069288
  2020-02-11 15:44:56.586 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: completedWrite(long) handle -&gt; 2852069288, byteCount -&gt; 68
  2020-02-11 15:44:56.591 22513-22513/com.cbmob.testapp I/Pull: Changed pull beer sample : Status{activityLevel=BUSY, progress=Progress{completed=0, total=0}, error=null}
  2020-02-11 15:44:56.591 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.write() handle -&gt; 2852069288
  2020-02-11 15:44:56.592 22513-22576/com.cbmob.testapp W/CouchbaseLite/NETWORK: completedWrite(long) handle -&gt; 2852069288, byteCount -&gt; 121
  2020-02-11 15:44:56.605 22513-22577/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.completedReceive() handle -&gt; 2852069288
  2020-02-11 15:44:56.608 22513-22577/com.cbmob.testapp I/chatty: uid=10086(com.cbmob.testapp) Thread-9 identical 1 line
  2020-02-11 15:44:56.612 22513-22577/com.cbmob.testapp W/CouchbaseLite/NETWORK: C4Socket.completedReceive() handle -&gt; 2852069288
  2020-02-11 15:44:56.627 22513-22513/com.cbmob.testapp I/Pull: Changed pull beer sample : Status{activityLevel=IDLE, progress=Progress{completed=0, total=0}, error=null}
  2020-02-11 15:44:56.628 22513-22513/com.cbmob.testapp E/Replication Comp Log: Scheduler Completed
  </code></pre>
  
  <p>Clearly the document changes in the db are not being logged. From this, I am assuming that the replication is not at all happening. I am not sure how to go about debugging this. If anyone has any pointers on how this can be debugged, I would appreciate it. If needed, I could post the sync gateway logs.</p>
  
  <p>If anyone has any links to any blogspots or projects which explains how to get all the pieces working together, kindly share that.</p>
  
  <p>Looking forward to hearing back from people.</p>