Search in sources :

Example 1 with CampaignProcessor

use of com.xrtb.bidder.CampaignProcessor in project XRTB by benmfaul.

the class TestCampaignProcessor method testNoCampaigns.

/**
	 * Test the situation where no campaigns are loaded in the system.
	 * @throws Exception when the bid JSON file fails to load or has a JSON error in it.
	 */
@Test
public void testNoCampaigns() throws Exception {
    InputStream is = Configuration.getInputStream("SampleBids/nexage.txt");
    BidRequest request = new BidRequest(is);
    AbortableCountDownLatch latch = new AbortableCountDownLatch(1, 1);
    CountDownLatch flag = new CountDownLatch(1);
    CampaignProcessor proc = new CampaignProcessor(null, request, flag, latch);
    flag.countDown();
    proc.run();
    SelectedCreative resp = proc.getSelectedCreative();
    // flag.countDown(); // back when proc was a thread
    try {
        latch.await();
        fail("This latch should have aborted");
    } catch (Exception e) {
    }
    assertNull(resp);
}
Also used : AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) InputStream(java.io.InputStream) CampaignProcessor(com.xrtb.bidder.CampaignProcessor) SelectedCreative(com.xrtb.bidder.SelectedCreative) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Example 2 with CampaignProcessor

use of com.xrtb.bidder.CampaignProcessor in project XRTB by benmfaul.

the class TestCampaignProcessor method testOneMatching.

/**
	 * Load a campaign and then use the bidder's campaign processor to make a bid response.
	 * @throws Exception if the config file or the sample bid file fails to load, or they contain JSON errors.
	 */
//	@Test
public void testOneMatching() throws Exception {
    InputStream is = Configuration.getInputStream("SampleBids/nexage.txt");
    BidRequest request = new BidRequest(is);
    Configuration cf = Configuration.getInstance();
    cf.clear();
    cf.initialize("Campaigns/payday.json");
    Campaign c = cf.campaignsList.get(0);
    AbortableCountDownLatch latch = new AbortableCountDownLatch(1, 1);
    CountDownLatch flag = new CountDownLatch(1);
    CampaignProcessor proc = new CampaignProcessor(c, request, flag, latch);
    flag.countDown();
    latch.await();
    SelectedCreative resp = proc.getSelectedCreative();
    assertNotNull(resp);
    assertTrue(resp.getCreative().dimensions.get(0).getLeftX() == 320);
}
Also used : Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) InputStream(java.io.InputStream) CampaignProcessor(com.xrtb.bidder.CampaignProcessor) SelectedCreative(com.xrtb.bidder.SelectedCreative) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) BidRequest(com.xrtb.pojo.BidRequest)

Aggregations

AbortableCountDownLatch (com.xrtb.bidder.AbortableCountDownLatch)2 CampaignProcessor (com.xrtb.bidder.CampaignProcessor)2 SelectedCreative (com.xrtb.bidder.SelectedCreative)2 BidRequest (com.xrtb.pojo.BidRequest)2 InputStream (java.io.InputStream)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Campaign (com.xrtb.common.Campaign)1 Configuration (com.xrtb.common.Configuration)1 Test (org.junit.Test)1