Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.sync.helpers; |
michael@0 | 5 | |
michael@0 | 6 | import static junit.framework.Assert.assertEquals; |
michael@0 | 7 | import static junit.framework.Assert.assertTrue; |
michael@0 | 8 | |
michael@0 | 9 | import java.util.HashSet; |
michael@0 | 10 | import java.util.concurrent.atomic.AtomicLong; |
michael@0 | 11 | |
michael@0 | 12 | import junit.framework.AssertionFailedError; |
michael@0 | 13 | |
michael@0 | 14 | import org.mozilla.gecko.sync.repositories.domain.Record; |
michael@0 | 15 | |
michael@0 | 16 | public class ExpectManyStoredDelegate extends DefaultStoreDelegate { |
michael@0 | 17 | HashSet<String> expectedGUIDs; |
michael@0 | 18 | AtomicLong stored; |
michael@0 | 19 | |
michael@0 | 20 | public ExpectManyStoredDelegate(Record[] records) { |
michael@0 | 21 | HashSet<String> s = new HashSet<String>(); |
michael@0 | 22 | for (Record record : records) { |
michael@0 | 23 | s.add(record.guid); |
michael@0 | 24 | } |
michael@0 | 25 | expectedGUIDs = s; |
michael@0 | 26 | stored = new AtomicLong(0); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | @Override |
michael@0 | 30 | public void onStoreCompleted(long storeEnd) { |
michael@0 | 31 | try { |
michael@0 | 32 | assertEquals(expectedGUIDs.size(), stored.get()); |
michael@0 | 33 | performNotify(); |
michael@0 | 34 | } catch (AssertionFailedError e) { |
michael@0 | 35 | performNotify(e); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | @Override |
michael@0 | 40 | public void onRecordStoreSucceeded(String guid) { |
michael@0 | 41 | try { |
michael@0 | 42 | assertTrue(expectedGUIDs.contains(guid)); |
michael@0 | 43 | } catch (AssertionFailedError e) { |
michael@0 | 44 | performNotify(e); |
michael@0 | 45 | } |
michael@0 | 46 | stored.incrementAndGet(); |
michael@0 | 47 | } |
michael@0 | 48 | } |