예제 #1
0
  public void testAddMissing() {
    Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 4, 5, 6)) buf.add(i, i);
    System.out.println("buf = " + buf);
    assert buf.size() == 5 && buf.getNumMissing() == 1;

    Integer num = buf.remove();
    assert num == 1;
    num = buf.remove();
    assert num == 2;
    num = buf.remove();
    assert num == null;

    buf.add(3, 3);
    System.out.println("buf = " + buf);
    assert buf.size() == 4 && buf.getNumMissing() == 0;

    for (int i = 3; i <= 6; i++) {
      num = buf.remove();
      System.out.println("buf = " + buf);
      assert num == i;
    }

    num = buf.remove();
    assert num == null;
  }
예제 #2
0
  public void testAddWithWrapAround() {
    Table<Integer> buf = new Table<Integer>(3, 10, 5);
    for (int i = 6; i <= 15; i++) assert buf.add(i, i) : "addition of seqno " + i + " failed";
    System.out.println("buf = " + buf);
    for (int i = 0; i < 3; i++) {
      Integer val = buf.remove(false);
      System.out.println("removed " + val);
      assert val != null;
    }
    System.out.println("buf = " + buf);

    long low = buf.getLow();
    buf.purge(8);
    System.out.println("buf = " + buf);
    assert buf.getLow() == 8;
    for (long i = low; i <= 8; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";

    for (int i = 16; i <= 18; i++) assert buf.add(i, i);
    System.out.println("buf = " + buf);

    while (buf.remove(false) != null) ;
    System.out.println("buf = " + buf);
    assert buf.isEmpty();
    assert buf.getNumMissing() == 0;
    low = buf.getLow();
    buf.purge(18);
    assert buf.getLow() == 18;
    for (long i = low; i <= 18; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";
  }
예제 #3
0
 public void remove(int[] indices) {
   // we need to remove the elements from our real storage as well
   scanningResults.remove(indices);
   super.remove(indices);
   // TODO: this is VERY slow if there are a lot of items (eg 300k), due to the Control.sort() that
   // is called inside to sort the indices
 }
예제 #4
0
  public void testRemove2() {
    final Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i : Arrays.asList(1, 2, 3, 4, 5)) buf.add(i, i);
    System.out.println("buf = " + buf);
    assertIndices(buf, 0, 0, 5);

    Integer el = buf.remove(true);
    System.out.println("el = " + el);
    assert el.equals(1);

    el = buf.remove(false); // not encouraged ! nullify should always be true or false
    System.out.println("el = " + el);
    assert el.equals(2);

    el = buf.remove(true);
    System.out.println("el = " + el);
    assert el.equals(3);
  }
예제 #5
0
 public static void testComputeSize2() {
   Table<Integer> table = new Table<Integer>(3, 10, 0);
   table.add(1, 1);
   System.out.println("table = " + table);
   assert table.computeSize() == table.size();
   assert table.computeSize() == 1;
   table.remove(false);
   System.out.println("table = " + table);
   assert table.computeSize() == table.size();
   assert table.computeSize() == 0;
 }
예제 #6
0
  public void testCompact2() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 80; i++) addAndGet(table, i);
    assert table.size() == 80;
    for (long i = 1; i <= 60; i++) table.remove();

    assert table.size() == 20;
    table.compact();
    assert table.size() == 20;
    assertCapacity(table.capacity(), table.getNumRows(), 10);
  }
예제 #7
0
  public void testPurge2() {
    Table<Integer> buf = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 7; i++) {
      buf.add(i, i);
      buf.remove(false);
    }
    System.out.println("buf = " + buf);
    assert buf.isEmpty();
    long low = buf.getLow();
    buf.purge(3);
    assert buf.getLow() == 3;
    for (long i = low; i <= 3; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";

    buf.purge(6);
    assert buf._get(6) == null;
    buf.purge(7);
    assert buf._get(7) == null;
    assert buf.getLow() == 7;
    assert buf.isEmpty();

    for (int i = 7; i <= 14; i++) {
      buf.add(i, i);
      buf.remove(false);
    }

    System.out.println("buf = " + buf);
    assert buf.isEmpty();

    low = buf.getLow();
    assert low == 7;
    buf.purge(12);
    System.out.println("buf = " + buf);
    assert buf.getLow() == 12;
    for (long i = low; i <= 12; i++)
      assert buf._get(i) == null : "message with seqno=" + i + " is not null";
  }
예제 #8
0
  public static void testPurge() {
    Table<Integer> table = new Table<Integer>(5, 10, 0);
    for (int seqno = 1; seqno <= 25; seqno++) table.add(seqno, seqno);

    int[] seqnos = {30, 31, 32, 37, 38, 39, 40, 41, 42, 47, 48, 49};
    for (int seqno : seqnos) table.add(seqno, seqno);

    System.out.println("table (before remove):\n" + table.dump());
    for (int seqno = 1; seqno <= 22; seqno++) table.remove(false);

    System.out.println("\ntable (after remove 22, before purge):\n" + table.dump());
    table.purge(22);
    System.out.println("\ntable: (after purge 22):\n" + table.dump());
    assert table.size() == 3 + seqnos.length;
    assert table.computeSize() == table.size();
  }
예제 #9
0
  public void testResizeWithPurge() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 100; i++) addAndGet(table, i);
    System.out.println("table: " + table);

    // now remove 60 messages
    for (int i = 1; i <= 60; i++) {
      Integer num = table.remove();
      assert num != null && num == i;
    }
    System.out.println("table after removal of seqno 60: " + table);

    table.purge(50);
    System.out.println("now triggering a resize() by addition of seqno=120");
    addAndGet(table, 120);
  }
예제 #10
0
 public void testIndex() {
   Table<Integer> buf = new Table<Integer>(3, 10, 5);
   assert buf.getHighestDelivered() == 5;
   assert buf.getHighestReceived() == 5;
   buf.add(6, 6);
   buf.add(7, 7);
   buf.remove(false);
   buf.remove(false);
   long low = buf.getLow();
   assert low == 5;
   buf.purge(4);
   buf.purge(5);
   buf.purge(6);
   buf.purge(7);
   System.out.println("buf = " + buf);
   for (long i = low; i <= 7; i++)
     assert buf._get(i) == null : "message with seqno=" + i + " is not null";
 }
 private void editMapping(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsMappings = fMappingsTable.getSelection();
   if (itemsMappings.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName());
     Mapping mapping = (Mapping) itemsMappings[0].getData();
     String idmapHMKey = mapping.getKey();
     idmapHM.remove(idmapHMKey);
     XMLCompareEditMappingDialog dialog =
         new XMLCompareEditMappingDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapHMKey = mapping.getKey();
       idmapHM.put(idmapHMKey, mapping.getIdAttribute());
       fMappingsTable.remove(fMappingsTable.indexOf(itemsMappings[0]));
       newMappingsTableItem(mapping, true);
     }
   }
 }
 private void editOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     String idmapALKey = mapping.getKey();
     idmapAL.remove(idmapALKey);
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapALKey = mapping.getKey();
       idmapAL.add(idmapALKey);
       fOrderedTable.remove(fOrderedTable.indexOf(itemsOrdered[0]));
       newOrderedTableItem(mapping, true);
     }
   }
 }
 private void renameIdMap(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   if (itemsIdMaps.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     String old_name = idmap.getName();
     String old_extension = idmap.getExtension();
     HashMap idmapHS = (HashMap) fIdMaps.get(old_name);
     XMLCompareAddIdMapDialog dialog =
         new XMLCompareAddIdMapDialog(
             shell, idmap, fIdMaps, fIdMapsInternal, fIdExtensionToName, true);
     if (dialog.open() == Window.OK) {
       fIdMaps.remove(old_name);
       fIdExtensionToName.remove(old_extension);
       fIdMaps.put(idmap.getName(), idmapHS);
       if (!idmap.getExtension().equals("")) // $NON-NLS-1$
       fIdExtensionToName.put(idmap.getExtension(), idmap.getName());
       fIdMapsTable.remove(fIdMapsTable.indexOf(itemsIdMaps[0]));
       newIdMapsTableItem(idmap, true);
     }
   }
 }
예제 #14
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   Rectangle clientArea = shell.getClientArea();
   table.setBounds(clientArea.x, clientArea.y, 200, 200);
   for (int i = 0; i < 128; i++) {
     TableItem item = new TableItem(table, SWT.NONE);
     item.setText("Item " + i);
   }
   Menu menu = new Menu(shell, SWT.POP_UP);
   table.setMenu(menu);
   MenuItem item = new MenuItem(menu, SWT.PUSH);
   item.setText("Delete Selection");
   item.addListener(SWT.Selection, event -> table.remove(table.getSelectionIndices()));
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
예제 #15
0
  public static void testRemove() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 9; i++) table.add(i, i);
    table.add(20, 20);
    System.out.println("table = " + table);
    assert table.size() == 10;
    assertIndices(table, 0, 0, 20);

    int num_null_msgs = table.getNumMissing();
    System.out.println("num_null_msgs = " + num_null_msgs);
    assert num_null_msgs == 10;

    for (long i = 1; i <= 10; i++) // 10 is missing
    table.remove();
    System.out.println("table = " + table);
    assert table.size() == 1;
    assertIndices(table, 9, 9, 20);

    num_null_msgs = table.getNumMissing();
    System.out.println("num_null_msgs = " + num_null_msgs);
    assert num_null_msgs == 10;
  }
예제 #16
0
  public void testResizeWithPurgeAndGetOfNonExistingElement() {
    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 50; i++) addAndGet(table, i);
    System.out.println("table: " + table);
    assertIndices(table, 0, 0, 50);
    assert table.size() == 50 && table.getNumMissing() == 0;

    // now remove 15 messages
    for (long i = 1; i <= 15; i++) {
      Integer num = table.remove(false);
      assert num != null && num == i;
    }
    System.out.println("table after removal of seqno 15: " + table);
    assertIndices(table, 0, 15, 50);
    assert table.size() == 35 && table.getNumMissing() == 0;

    table.purge(15);
    System.out.println("now triggering a resize() by addition of seqno=55");
    addAndGet(table, 55);
    assertIndices(table, 15, 15, 55);
    assert table.size() == 36 && table.getNumMissing() == 4;

    // now we have elements 40-49 in row 1 and 55 in row 2:
    List<Integer> list = new ArrayList<Integer>(20);
    for (int i = 16; i < 50; i++) list.add(i);
    list.add(55);

    for (long i = table.getOffset(); i < table.capacity() + table.getOffset(); i++) {
      Integer num = table._get(i);
      if (num != null) {
        System.out.println("num=" + num);
        list.remove(num);
      }
    }

    System.out.println("table:\n" + table.dump());
    assert list.isEmpty() : " list: " + Util.print(list);
  }
예제 #17
0
  public static void testGetNullMessages2() {
    Table<Integer> table = new Table<Integer>(1, 10, 0);
    table.add(1, 1);
    table.add(5, 5);
    System.out.println("table = " + table);
    int num_null_elements = table.getNumMissing();
    assert num_null_elements == 3; // [2 .. 4]

    table.add(10, 10);
    System.out.println("table = " + table);
    assert table.size() == 3;
    assert table.getNumMissing() == 7;

    table.add(14, 14);
    System.out.println("table = " + table);
    assert table.size() == 4;
    assert table.getNumMissing() == 10;

    while (table.remove() != null) ;
    System.out.println("table = " + table);
    assert table.size() == 3;
    assert table.getNumMissing() == 10;
  }
예제 #18
0
  @Test
  public void mustFailOnWriteInReadTransactions() {
    SharedGroup db = new SharedGroup(testFile, SharedGroup.Durability.FULL, null);

    writeOneTransaction(db, 1);

    ReadTransaction t = db.beginRead();
    Table table = t.getTable("EmployeeTable");

    try {
      table.addEmptyRow();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.addEmptyRows(1);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.clear();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.optimize();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.remove(0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.removeLast();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setBinaryByteArray(0, 0, null);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setBoolean(0, 0, false);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setDate(0, 0, new Date(0));
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.addSearchIndex(0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setLong(0, 0, 0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setMixed(0, 0, null);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      table.setString(0, 0, "");
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }

    TableQuery q = table.where();
    try {
      q.remove();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      q.remove(0, 0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }

    TableView v = q.findAll();
    try {
      v.clear();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.remove(0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.removeLast();
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setBinaryByteArray(0, 0, null);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setBoolean(0, 0, false);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setDate(0, 0, new Date());
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setLong(0, 0, 0);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setString(0, 0, "");
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }
    try {
      v.setMixed(0, 0, null);
      fail();
    } catch (IllegalStateException e) {
      assertNotNull(e);
    }

    t.endRead();
  }