@Nonnull @Override protected Billing newBilling() { final Billing billing = super.newBilling(); billing.setMainThread(sameThreadExecutor()); return billing; }
@Nonnull @Override protected Billing newBilling() { final Billing billing = super.newBilling(); billing.setMainThread(sameThreadExecutor()); return billing; }
@Nonnull static Billing newSynchronousBilling() { final Billing billing = new Billing(RuntimeEnvironment.application, newConfiguration(true, false)); billing.setPurchaseVerifier(Tests.newMockVerifier(true)); final IInAppBillingService service = mock(IInAppBillingService.class); final CancellableExecutor sameThreadExecutor = sameThreadExecutor(); billing.setBackground(sameThreadExecutor); billing.setMainThread(sameThreadExecutor); setService(billing, service); return billing; }
@Before public void setUp() throws Exception { final Billing billing = Tests.newBilling(); billing.setMainThread(sameThreadExecutor()); mRequest = Inventory.Request.create().loadSkus(IN_APP, asList("sku_0", "sku_1", "sku_2", "sku_3", "sku_4", "sku_6")).loadAllPurchases(); mCheckout = Checkout.forApplication(billing); mDb = new BillingDB(RuntimeEnvironment.application); }
@Test public void testShouldRunAllRequests() throws Exception { final int REQUESTS = 100; final int SLEEP = 10; final Billing b = Tests.newBilling(false); b.setMainThread(Tests.sameThreadExecutor()); final AsyncServiceConnector c = new AsyncServiceConnector(b); b.setConnector(c); final CountDownLatch latch = new CountDownLatch(REQUESTS); final RequestListener l = new CountDownListener(latch); for (int i = 0; i < REQUESTS; i++) { if (i % 10 == 0) { if (mRandom.nextBoolean()) { b.connect(); } else { // connector is called directly in order to avoid cancelling the pending // requests c.disconnect(); } } b.runWhenConnected(new SleepingRequest(mRandom.nextInt(SLEEP)), l, null); } b.connect(); assertTrue(latch.await(SLEEP * REQUESTS, TimeUnit.MILLISECONDS)); }