示例#1
0
  public void testConfirmEmp() throws Exception {
    LegContainer<EmpEntry> container = craken.defineLeg(EmpEntry.class);

    for (EntryKey key : container.keySet()) {
      Debug.line(container.findByKey(key));
    }
  }
示例#2
0
  public void testCreate() throws Exception {
    craken
        .globalConfig()
        .transport()
        .clusterName("my-cluster")
        .addProperty("configurationFile", "resource/config/jgroups-udp.xml");
    craken.start();
    LegContainer<SimpleEntry> container =
        craken.defineLeg(
            SimpleEntry.class,
            new ConfigurationBuilder()
                .clustering()
                .cacheMode(CacheMode.REPL_SYNC)
                .jmxStatistics()
                .enable()
                .clustering()
                .invocationBatching()
                .build());
    craken.addListener(new ContainerListener());

    // container.addListener(new EntryListener()) ;

    while (true) {
      SimpleEntry node =
          container
              .newInstance("bleujin" + RandomUtil.nextInt(10))
              .put("age", RandomUtil.nextInt(100))
              .put("server", craken.getManager().getAddress().toString());
      node.save();
      Thread.sleep(1000);
    }
  }
示例#3
0
  public void testFind() throws Exception {
    LegContainer<SimpleEntry> container = craken.defineLeg(SimpleEntry.class);

    for (int i = 0; i < 15; i++) {
      container.newInstance("user" + i).put("index", i).save();
    }

    List<SimpleEntry> found =
        container.findInMemory(
            new EntryFilter<SimpleEntry>() {
              public boolean filter(SimpleEntry node) {
                return node.fieldAsInt("index") < 5;
              }
            });

    assertEquals(5, found.size());

    List<SimpleEntry> foundPage =
        container.find(
            new EntryFilter<SimpleEntry>() {
              public boolean filter(SimpleEntry node) {
                return node.fieldAsInt("index") < 5;
              }
            },
            Page.create(2, 2));

    assertEquals(2, foundPage.size());
  }
示例#4
0
  public void testRET() throws Exception {
    LegContainer<SimpleEntry> container = craken.defineLeg(SimpleEntry.class);

    container.newInstance("bleujin").put("name", "bleujin").put("age", 20).save();
    container.newInstance(7756).put("name", "hero").put("age", 364).save();

    SimpleEntry bleujin = container.findByKey("bleujin");
    Debug.line(bleujin.field("age"), bleujin.fieldAsInt("age") + 1, bleujin.fieldAsString("name"));

    SimpleEntry f7756 = container.findByKey(7756);
    Debug.line(f7756.field("age"), f7756.fieldAsInt("age") + 1, f7756.fieldAsString("name"));
  }
示例#5
0
  public void testFindOne() throws Exception {
    LegContainer<SimpleEntry> container = craken.defineLeg(SimpleEntry.class);

    container.newInstance("bleujin").put("name", "bleujin").put("age", 20).save();
    container.newInstance(7756).put("name", "hero").put("age", 364).save();

    SimpleEntry found =
        container.findOneInMemory(
            new EntryFilter<SimpleEntry>() {
              public boolean filter(SimpleEntry node) {
                return node.fieldAsInt("age") > 100;
              }
            });

    assertEquals(364, found.fieldAsInt("age"));
  }
示例#6
0
  public void testEmpNode() throws Exception {
    LegContainer<EmpEntry> container =
        craken.defineLeg(
            EmpEntry.class,
            new ConfigurationBuilder()
                .clustering()
                .cacheMode(CacheMode.REPL_SYNC)
                .jmxStatistics()
                .enable()
                .clustering()
                .invocationBatching()
                .build());
    //		container.addListener(new EntryListener()) ;

    EmpEntry emp = container.newInstance("7789");
    emp.name("bleujin").age(20);
    emp.save();

    assertEquals("bleujin", container.findByKey("7789").name());
  }