Search in sources :

Example 1 with Bid

use of com.xrtb.pojo.Bid in project XRTB by benmfaul.

the class TestWinProcessing method testCappingTimes1.

@Test
public void testCappingTimes1() throws Exception {
    redisson.del("capped_blocker166.137.138.18");
    for (Campaign c : Configuration.getInstance().campaignsList) {
        if (c.adId.equals("ben:payday")) {
            for (Creative cc : c.creatives) {
                if (cc.impid.equals("blocker")) {
                    cc.capFrequency = 1;
                    break;
                }
            }
        }
    }
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage50x50.txt")))).toString();
    // Get 1 time is ok, but 2d time is a no bid
    String s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    int rc = http.getResponseCode();
    assertTrue(rc == 200);
    String value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value == null);
    Bid win = new Bid(s);
    String repl = win.nurl.replaceAll("\\$", "");
    win.nurl = repl.replace("{AUCTION_PRICE}", ".05");
    System.out.println(win.nurl);
    s = http.sendPost(win.nurl, "", 30000, 30000);
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    // better no bid.
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    rc = http.getResponseCode();
    assertTrue(rc == 204);
    assertNull(s);
    rc = http.getResponseCode();
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    System.out.println("DONE!");
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) HttpPostGet(com.xrtb.common.HttpPostGet) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Example 2 with Bid

use of com.xrtb.pojo.Bid in project XRTB by benmfaul.

the class TestWinProcessing method testWinProcessingSmartyAds.

/**
	 * Test the basic win processing system of the RTB
	 * @throws Exception on networking problems.
	 */
@Test
public void testWinProcessingSmartyAds() throws Exception {
    HttpPostGet http = new HttpPostGet();
    redisson.del("35c22289-06e2-48e9-a0cd-94aeb79fab43");
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    /**
		 * Send the bid
		 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/smartyads", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    int x = s.indexOf("{bid_id");
    assertTrue(x == -1);
    x = s.indexOf("%7Bbid_id");
    assertTrue(x == -1);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    // Now retrieve the bid information from the cache
    Map m = redisson.hgetAll(bid.id);
    assertTrue(!m.isEmpty());
    String price = (String) m.get("PRICE");
    assertTrue(!price.equals("0.0"));
    /**
		 * Send the win notification
		 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "");
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    System.out.println(s);
    x = s.indexOf("{creative_");
    assertTrue(x == -1);
    /*
		 * Make sure the returned adm is not crap html 
		 */
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(s));
    //	Document doc = db.parse(is);
    // Check to see the bid was removed from the cache
    m = redisson.hgetAll(bid.id);
    assertNull(m);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpPostGet(com.xrtb.common.HttpPostGet) StringReader(java.io.StringReader) Bid(com.xrtb.pojo.Bid) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Bid

use of com.xrtb.pojo.Bid in project XRTB by benmfaul.

the class TestWinProcessing method testWinProcessingNexage.

/**
	 * Test the basic win processing system of the RTB
	 * @throws Exception on networking problems.
	 */
@Test
public void testWinProcessingNexage() throws Exception {
    HttpPostGet http = new HttpPostGet();
    redisson.del("35c22289-06e2-48e9-a0cd-94aeb79fab43");
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    /**
		 * Send the bid
		 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    int x = s.indexOf("{bid_id");
    assertTrue(x == -1);
    x = s.indexOf("%7Bbid_id");
    assertTrue(x == -1);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    // Now retrieve the bid information from the cache
    Map m = redisson.hgetAll(bid.id);
    assertTrue(!m.isEmpty());
    String price = (String) m.get("PRICE");
    assertNotNull(price);
    assertTrue(!price.equals("0.0"));
    /**
		 * Send the win notification
		 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "");
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    assertNotNull(s);
    /*
		 * Make sure the returned adm is not crap html 
		 */
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(s));
    //	Document doc = db.parse(is);
    // Check to see the bid was removed from the cache
    m = redisson.hgetAll(bid.id);
    assertNull(m);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpPostGet(com.xrtb.common.HttpPostGet) StringReader(java.io.StringReader) Bid(com.xrtb.pojo.Bid) Map(java.util.Map) Test(org.junit.Test)

Example 4 with Bid

use of com.xrtb.pojo.Bid in project XRTB by benmfaul.

the class TestWinProcessing method testWinProcessingAtomx.

@Test
public void testWinProcessingAtomx() throws Exception {
    HttpPostGet http = new HttpPostGet();
    redisson.del("35c22289-06e2-48e9-a0cd-94aeb79fab43");
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    /**
		 * Send the bid
		 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/atomx", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    int x = s.indexOf("{bid_id");
    assertTrue(x == -1);
    x = s.indexOf("%7Bbid_id");
    assertTrue(x == -1);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    // Now retrieve the bid information from the cache
    Map m = redisson.hgetAll(bid.id);
    assertTrue(!m.isEmpty());
    String price = (String) m.get("PRICE");
    assertNotNull(price);
    assertTrue(!price.equals("0.0"));
    /**
		 * Send the win notification
		 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "");
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    System.out.println(s);
    x = s.indexOf("{creative_");
    assertTrue(x == -1);
    /*
		 * Make sure the returned adm is not crap html 
		 */
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(s));
    //	Document doc = db.parse(is);
    // Check to see the bid was removed from the cache
    m = redisson.hgetAll(bid.id);
    assertNull(m);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpPostGet(com.xrtb.common.HttpPostGet) StringReader(java.io.StringReader) Bid(com.xrtb.pojo.Bid) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Bid

use of com.xrtb.pojo.Bid in project XRTB by benmfaul.

the class TestWinProcessing method testNegative.

@Test
public void testNegative() throws Exception {
    HttpPostGet http = new HttpPostGet();
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch wlatch = new CountDownLatch(1);
    final List<Double> price = new ArrayList();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/negative.txt")))).toString();
    com.xrtb.jmq.RTopic channel = new com.xrtb.jmq.RTopic("tcp://*:5571&bids");
    channel.subscribe("bids");
    channel.addListener(new com.xrtb.jmq.MessageListener<BidResponse>() {

        @Override
        public void onMessage(String channel, BidResponse bid) {
            price.add(bid.cost);
            System.out.println("BID COST: " + bid.cost);
            latch.countDown();
        }
    });
    com.xrtb.jmq.RTopic wchannel = new com.xrtb.jmq.RTopic("tcp://*:5572&wins");
    wchannel.subscribe("wins");
    wchannel.addListener(new com.xrtb.jmq.MessageListener<WinObject>() {

        @Override
        public void onMessage(String channel, WinObject win) {
            ;
            price.add(new Double(win.price));
            price.add(new Double(win.cost));
            wlatch.countDown();
        }
    });
    /**
			 * Send the bid request
			 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    assertEquals(bid.price, 1.1, .001);
    /**
			 * Send the win notification
			 */
    try {
        price.clear();
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", Double.toString(bid.price));
        s = http.sendPost(bid.nurl, "", 300000, 300000);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    long time = 5;
    assertTrue(s.length() > 10);
    wlatch.await(time, TimeUnit.SECONDS);
    assertTrue(price.get(0) == 1.1);
    System.out.println("xxxxxx: " + price.get(1));
    assertTrue(price.get(1) == 1.1);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) ArrayList(java.util.ArrayList) WinObject(com.xrtb.pojo.WinObject) CountDownLatch(java.util.concurrent.CountDownLatch) BidResponse(com.xrtb.pojo.BidResponse) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Aggregations

HttpPostGet (com.xrtb.common.HttpPostGet)9 Bid (com.xrtb.pojo.Bid)9 Test (org.junit.Test)9 StringReader (java.io.StringReader)5 Map (java.util.Map)5 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 InputSource (org.xml.sax.InputSource)5 Campaign (com.xrtb.common.Campaign)2 Creative (com.xrtb.common.Creative)2 BidResponse (com.xrtb.pojo.BidResponse)1 WinObject (com.xrtb.pojo.WinObject)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1