Search in sources :

Example 21 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class Config method setup.

/** 
	 * JUNIT Test configuration for shards.
	 * 
	 */
public static void setup(String shard, int port) throws Exception {
    try {
        if (server == null) {
            DbTools tools = new DbTools(redisHost);
            tools.clear();
            tools.loadDatabase("database.json");
            server = new RTBServer("./Campaigns/payday.json", shard, port, port + 1);
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools)

Example 22 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class Config method setup.

public static void setup() throws Exception {
    try {
        DbTools tools = new DbTools("localhost:3000");
        tools.clear();
        tools.loadDatabase("database.json");
        if (server == null) {
            server = new RTBServer("./Campaigns/payday.json");
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
            if (server.getCampaigns().size() == 0) {
                fail("NO CAMPAIGNS LOADED");
            }
            Thread.sleep(1000);
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools)

Example 23 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class TestAdx method testSetup.

@BeforeClass
public static void testSetup() {
    try {
        DbTools tools = new DbTools("localhost:3000");
        tools.clear();
        tools.loadDatabase("database.json");
        if (server == null) {
            server = new RTBServer("./Campaigns/payday.json");
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
            Thread.sleep(1000);
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools) BeforeClass(org.junit.BeforeClass)

Example 24 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class TestDatabase method makeFile.

/**
	 * Test making the user database from scratch/
	 * @throws Exception on JSON parsing of the file.
	 */
@Test
public void makeFile() throws Exception {
    List<User> list = new ArrayList();
    User u = new User("ben");
    list.add(u);
    String content = new String(Files.readAllBytes(Paths.get("stub.json")));
    Campaign c = new Campaign(content);
    c.adId = "ben:new-campaign";
    u.campaigns.add(c);
    assertTrue(c.date.size() == 2);
    content = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(list);
    System.out.println(content);
    ;
    System.out.println("-------------------------");
    List<User> x = DbTools.mapper.readValue(content, DbTools.mapper.getTypeFactory().constructCollectionType(List.class, User.class));
    User z = x.get(0);
    System.out.println(z);
}
Also used : User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 25 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class JunkDomainUser method testTwoThreadAccessDatabase.

/*@Test
	public void testSingleThreadAccess()  {
		User u = new User();
		u.name = "Ben";
		
		try {
			db.getInstance().put(u);
			u = null;
			u = db.getInstance().get("Ben");
			assertTrue(u.name.equals("Ben"));
			
		} catch (Exception e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}*/
@Test
public void testTwoThreadAccessDatabase() {
    User u = new User();
    u.name = "Ben";
    CountDownLatch latch = new CountDownLatch(2);
    CountDownLatch flag = new CountDownLatch(1);
    JunkUser ben = new JunkUser(flag, latch, "Ben");
    JunkUser peter = new JunkUser(flag, latch, "Peter");
    flag.countDown();
    try {
        latch.await(5, TimeUnit.SECONDS);
        System.out.println("Check ben");
        u = db.get("Ben");
        System.out.println("BEN: " + DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(u));
        assertTrue(u.name.equals("Ben"));
        u = null;
        System.out.println("Check peter");
        u = db.get("Peter");
        System.out.println("Peter" + DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(u));
        assertTrue(u.name.equals("Peter"));
        db.clear();
        Thread.sleep(200);
        u = db.get("Ben");
        assertNull(u);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : User(com.xrtb.db.User) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

User (com.xrtb.db.User)28 Campaign (com.xrtb.common.Campaign)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 Map (java.util.Map)9 List (java.util.List)7 RTBServer (com.xrtb.bidder.RTBServer)5 Configuration (com.xrtb.common.Configuration)5 DbTools (com.xrtb.tools.DbTools)5 Test (org.junit.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Node (com.xrtb.common.Node)3 BidRequest (com.xrtb.pojo.BidRequest)3 File (java.io.File)2 Set (java.util.Set)2 HttpSession (javax.servlet.http.HttpSession)2 BeforeClass (org.junit.BeforeClass)2 AddCampaign (com.xrtb.commands.AddCampaign)1 DeleteCampaign (com.xrtb.commands.DeleteCampaign)1 DataBaseObject (com.xrtb.db.DataBaseObject)1