Skip to content

Commit a91aeeb

Browse files
fix(location) Wire up trackerName (#2298)
1 parent ae1e3d4 commit a91aeeb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

aws-android-sdk-location/src/main/java/com/amazonaws/mobileconnectors/geo/tracker/AWSLocationTracker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public synchronized void startTracking(
144144
this.trackingPublisher = new TrackingPublisher(
145145
locationClient,
146146
deviceId,
147+
trackerName,
147148
5,
148149
options.getEmitLocationFrequency() == null ?
149150
DEFAULT_EMIT_LOCATION_FREQUENCY :

aws-android-sdk-location/src/main/java/com/amazonaws/mobileconnectors/geo/tracker/TrackingPublisher.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ public class TrackingPublisher {
4444
private static final long TERMINATION_TIMEOUT_MS = 10;
4545

4646
private final String deviceId;
47+
private final String trackerName;
4748
private final LinkedBlockingQueue<DevicePositionUpdate> positionUpdateQueue;
4849
private final LinkedBlockingQueue<BatchUpdateDevicePositionRequest> batchRequestQueue;
4950
private final ScheduledFuture<?> scheduledFuture;
5051
private final ScheduledExecutorService scheduledExecutorService;
5152
private final BatchPublisher batchPublisher;
5253

5354
public TrackingPublisher(AmazonLocationClient locationClient,
54-
String deviceId) {
55+
String deviceId,
56+
String trackerName) {
5557
this(locationClient,
5658
deviceId,
59+
trackerName,
5760
DEFAULT_WORKER_POOL_SIZE,
5861
DEFAULT_PUBLISH_INTERVAL_MS,
5962
DEFAULT_BATCH_SIZE,
@@ -62,12 +65,14 @@ public TrackingPublisher(AmazonLocationClient locationClient,
6265

6366
public TrackingPublisher(AmazonLocationClient locationClient,
6467
String deviceId,
68+
String trackerName,
6569
int workerPoolSize,
6670
long publishIntervalMillis,
6771
int batchSize,
6872
TrackingListener listener) {
6973
this(locationClient,
7074
deviceId,
75+
trackerName,
7176
Executors.newScheduledThreadPool(workerPoolSize),
7277
publishIntervalMillis,
7378
batchSize,
@@ -76,11 +81,13 @@ public TrackingPublisher(AmazonLocationClient locationClient,
7681

7782
public TrackingPublisher(AmazonLocationClient locationClient,
7883
String deviceId,
84+
String trackerName,
7985
ScheduledExecutorService scheduledExecutorService,
8086
long publishIntervalMillis,
8187
int batchSize,
8288
TrackingListener listener) {
8389
this.deviceId = deviceId;
90+
this.trackerName = trackerName;
8491
positionUpdateQueue = new LinkedBlockingQueue<>(batchSize);
8592
batchRequestQueue = new LinkedBlockingQueue<>();
8693
batchPublisher = new BatchPublisher(locationClient, batchRequestQueue, listener);
@@ -185,7 +192,7 @@ private void flush(boolean force) {
185192
*/
186193
private BatchUpdateDevicePositionRequest createNewBatch() {
187194
BatchUpdateDevicePositionRequest batch = new BatchUpdateDevicePositionRequest();
188-
batch.setTrackerName(deviceId);
195+
batch.setTrackerName(trackerName);
189196
batch.setUpdates(new ArrayList<DevicePositionUpdate>());
190197
return batch;
191198
}

aws-android-sdk-location/src/test/java/mobileconnectors/geo/tracker/TrackingPublisherTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.Before;
2525
import org.junit.Test;
2626
import org.junit.runner.RunWith;
27+
import org.mockito.ArgumentCaptor;
2728
import org.robolectric.RobolectricTestRunner;
2829
import org.robolectric.shadows.ShadowLog;
2930

@@ -45,6 +46,7 @@ public class TrackingPublisherTest {
4546
private static final long PUBLISH_INTERVAL_MS = TimeUnit.SECONDS.toMillis(2);
4647
private static final int BATCH_SIZE = 10;
4748
private static final long LATCH_WAIT_BASE_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(3);
49+
private static final String TRACKER_NAME = "TRACKER_NAME";
4850

4951
private TrackingPublisher trackingPublisher;
5052
private AmazonLocationClient mockLocationClient;
@@ -55,6 +57,7 @@ public void setup() {
5557
mockLocationClient = mock(AmazonLocationClient.class);
5658
trackingPublisher = new TrackingPublisher(mockLocationClient,
5759
"UNIT_TEST_DEVICE_ID",
60+
TRACKER_NAME,
5861
WORKER_POOL_SIZE,
5962
PUBLISH_INTERVAL_MS,
6063
BATCH_SIZE,
@@ -104,7 +107,14 @@ public void enqueueMoreThanBatchSizeTest() throws InterruptedException {
104107

105108
latch.await(LATCH_WAIT_BASE_TIMEOUT_MS * expectedNumOfBatchesPublished, TimeUnit.SECONDS);
106109
// The client should have been called once.
107-
verify(mockLocationClient, times(expectedNumOfBatchesPublished)).batchUpdateDevicePosition(any(BatchUpdateDevicePositionRequest.class));
110+
ArgumentCaptor<BatchUpdateDevicePositionRequest> requestArgumentCaptor =
111+
ArgumentCaptor.forClass(BatchUpdateDevicePositionRequest.class);
112+
verify(mockLocationClient,
113+
times(expectedNumOfBatchesPublished)).batchUpdateDevicePosition(requestArgumentCaptor.capture());
114+
115+
// Verify the tracker name was set to the expected value.
116+
assertEquals(TRACKER_NAME, requestArgumentCaptor.getValue().getTrackerName());
117+
108118
// No pending batches should be left.
109119
assertEquals(0, trackingPublisher.pendingBatches());
110120
}

0 commit comments

Comments
 (0)