Skip to content

Commit

Permalink
Merge branch 'master' into tt--layer-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
githengi authored Jan 19, 2021
2 parents e55cc60 + 65f5f63 commit 9f3f0ae
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 59 deletions.
11 changes: 5 additions & 6 deletions opensrp-reveal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ android {
applicationId "org.smartregister.reveal"
minSdkVersion 18
targetSdkVersion 28
versionCode 29
versionName "5.3.16"
versionCode 30
versionName "5.3.17"
multiDexEnabled true
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand Down Expand Up @@ -125,7 +125,7 @@ android {
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", 'opensrp_base_url', '"https://reveal-zm.smartregister.org/opensrp/"'
buildConfigField "Integer", "DATABASE_VERSION", '12'
buildConfigField "Integer", "DATABASE_VERSION", '13'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
Expand All @@ -143,7 +143,7 @@ android {

debug {
resValue "string", 'opensrp_base_url', '"https://reveal-stage.smartregister.org/opensrp/"'
buildConfigField "Integer", "DATABASE_VERSION", '12'
buildConfigField "Integer", "DATABASE_VERSION", '13'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
Expand Down Expand Up @@ -180,8 +180,7 @@ android {

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
maxHeapSize = "2g"
//testLogging.showStandardStreams = true
maxHeapSize = "4g"

testLogging {
events TestLogEvent.FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 12:
upgradeToVersion12(db);
break;
case 13:
upgradeToVersion13(db);
break;
default:
break;
}
Expand Down Expand Up @@ -285,6 +288,10 @@ private void upgradeToVersion12(SQLiteDatabase db) {
TaskRepository.updatePriorityToEnumAndAddRestrictions(db);
}

private void upgradeToVersion13(SQLiteDatabase db) {
db.execSQL(String.format("UPDATE %s set %s = ? WHERE %s=? ", EVENT_TABLE, DatabaseKeys.SYNC_STATUS, DatabaseKeys.SYNC_STATUS), new String[]{BaseRepository.TYPE_Unsynced, BaseRepository.TYPE_Task_Unprocessed});
}

private void clientProcessEvents(List<String> eventTypes) {
//client process events after 5 seconds so that get calls to getDatabase return
new Timer().schedule(new TimerTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import android.app.IntentService;
import android.content.Intent;

import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import org.smartregister.domain.FetchStatus;
import org.smartregister.domain.Location;
import org.smartregister.domain.Task;
import org.smartregister.domain.db.EventClient;
import org.smartregister.job.SyncServiceJob;
import org.smartregister.receiver.SyncStatusBroadcastReceiver;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.TaskRepository;
import org.smartregister.reveal.application.RevealApplication;
import org.smartregister.reveal.job.RevealSyncSettingsServiceJob;
Expand All @@ -25,10 +23,7 @@
import org.smartregister.util.NetworkUtils;
import org.smartregister.util.SyncUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import timber.log.Timber;

Expand Down Expand Up @@ -114,8 +109,6 @@ private void doSync() {
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}

clientProcessEvents(extractStructureIds(syncedStructures, synchedTasks));

if (!org.smartregister.util.Utils.isEmptyCollection(syncedStructures)
|| !org.smartregister.util.Utils.isEmptyCollection(synchedTasks)) {
doSync();
Expand Down Expand Up @@ -162,41 +155,5 @@ private boolean hasChangesInCurrentOperationalArea(List<Location> syncedStructur
return false;
}

/**
* Extracts a set of Structures ids from syched structures and tasks
*
* @param syncedStructures the list of synced structures
* @param synchedTasks the list of synced tasks
* @return a set of baseEntityIds
*/
private Set<String> extractStructureIds(List<Location> syncedStructures, List<Task> synchedTasks) {
Set<String> structureIds = new HashSet<>();
if (!org.smartregister.util.Utils.isEmptyCollection(syncedStructures)) {
for (Location structure : syncedStructures) {
structureIds.add(structure.getId());
}
}
if (!org.smartregister.util.Utils.isEmptyCollection(synchedTasks)) {
for (Task task : synchedTasks) {
structureIds.add(task.getForEntity());
}
}
return structureIds;
}

/**
* Clients Processes events of a set of structure baseEntityIds that have the task status TYPE_Task_Unprocessed
*
* @param syncedStructuresIds the set of structure baseEntityIds to client process
*/
private void clientProcessEvents(Set<String> syncedStructuresIds) {
if (org.smartregister.util.Utils.isEmptyCollection(syncedStructuresIds))
return;
EventClientRepository ecRepository = RevealApplication.getInstance().getContext().getEventClientRepository();
List<EventClient> eventClients = ecRepository.getEventsByBaseEntityIdsAndSyncStatus(BaseRepository.TYPE_Task_Unprocessed, new ArrayList<>(syncedStructuresIds));
if (!eventClients.isEmpty()) {
RevealClientProcessor.getInstance(getApplicationContext()).processClient(eventClients);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,9 @@ private String updateTask(Event event, boolean localEvents) {
if (localEvents && BaseRepository.TYPE_Synced.equals(task.getSyncStatus())) {
task.setSyncStatus(BaseRepository.TYPE_Unsynced);
revealApplication.setSynced(false);
} else if (!localEvents && event.getServerVersion() != 0 && !CoreLibrary.getInstance().isPeerToPeerProcessing()) {
// for events synced from server and task exists mark events as being fully synced
eventClientRepository.markEventAsSynced(event.getFormSubmissionId());
}
taskRepository.addOrUpdate(task);
operationalAreaId = task.getGroupIdentifier();
} else if (!localEvents) {
eventClientRepository.markEventAsTaskUnprocessed(event.getFormSubmissionId());
}
return operationalAreaId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testUpdateTaskShouldMarkEventAsTaskUnprocessed() throws Exception {

Whitebox.invokeMethod(clientProcessor, "updateTask", event, false);

verify(eventClientRepository).markEventAsTaskUnprocessed(eq(FORM_SUBMISSION_ID));
verify(eventClientRepository,never()).markEventAsTaskUnprocessed(eq(FORM_SUBMISSION_ID));
}

@Test
Expand All @@ -175,7 +175,7 @@ public void testUpdateTaskShouldMarkEventAsSynced() throws Exception {

Whitebox.invokeMethod(clientProcessor, "updateTask", event, false);

verify(eventClientRepository).markEventAsSynced(eq(FORM_SUBMISSION_ID));
verify(eventClientRepository,never()).markEventAsSynced(eq(FORM_SUBMISSION_ID));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testProcessEventClientWithoutTasksAndLocations() {
Whitebox.setInternalState(clientProcessor, "eventClientRepository", eventClientRepository);
clientProcessor.processClient(Arrays.asList(new EventClient(event, null), new EventClient(sprayedEvent, null)), false);

verify(eventClientRepository, times(2)).markEventAsTaskUnprocessed(anyString());
verify(eventClientRepository, never()).markEventAsTaskUnprocessed(anyString());
}

@Test
Expand All @@ -182,7 +182,7 @@ public void testProcessEventClientShouldUpdateTaskStatusOnlyForRemoteEvents() {
clientProcessor.processClient(Collections.singletonList(new EventClient(sprayedEvent, null)));

verify(eventClientRepository, never()).markEventAsTaskUnprocessed(sprayedEvent.getFormSubmissionId());
verify(eventClientRepository).markEventAsSynced(sprayedEvent.getFormSubmissionId());
verify(eventClientRepository,never()).markEventAsSynced(sprayedEvent.getFormSubmissionId());

verify(taskRepository).addOrUpdate(taskCaptor.capture());

Expand Down

0 comments on commit 9f3f0ae

Please sign in to comment.