@Test public void testAddBindings() throws Exception { assertEquals(0, database.addBindings(mergeBindings()).size()); assertEquals(0, database.getBindings().size()); List<SxpBindingFields> toAdd = mergeBindings(getBinding("0.0.0.0/0", 5, "10.10.10.10"), getBinding("1.1.1.1/32", 10, "10.10.10.10"), getBinding("1.1.1.1/32", 100, "10.10.10.10"), getBinding("2.2.2.2/32", 20, "20.20.20.20", "10.10.10.10"), getBinding("2.2.2.2/32", 200, "20.20.20.20")); assertBindings(database.addBindings(toAdd), mergeBindings(getBinding("1.1.1.1/32", 100, "10.10.10.10"), getBinding("2.2.2.2/32", 200, "20.20.20.20"))); assertEquals(2, database.getBindings().size()); assertBindings(database.getBindings(), mergeBindings(getBinding("1.1.1.1/32", 100, "10.10.10.10"), getBinding("2.2.2.2/32", 200, "20.20.20.20"))); assertEquals(0, database.addBindings(toAdd).size()); assertEquals(2, database.getBindings().size()); assertBindings(database.getBindings(), mergeBindings(getBinding("1.1.1.1/32", 100, "10.10.10.10"), getBinding("2.2.2.2/32", 200, "20.20.20.20"))); toAdd.clear(); toAdd = mergeBindings(getBinding("15.15.15.15/24", 15, "0.10.10.10"), getBinding("2.2.2.2/32", 2000, "200.200.200.200")); assertEquals(2, database.addBindings(toAdd).size()); assertEquals(3, database.getBindings().size()); assertBindings(database.getBindings(), mergeBindings(getBinding("1.1.1.1/32", 100, "10.10.10.10"), getBinding("2.2.2.2/32", 2000, "20.20.20.20"), getBinding("15.15.15.15/24", 15, "0.10.10.10"), getBinding("2.2.2.2/32", 2000, "200.200.200.200"))); }
@Override public synchronized <T extends SxpBindingFields> List<MasterDatabaseBinding> addBindings(List<T> bindings) { List<MasterDatabaseBinding> added = new ArrayList<>(); if (bindings == null) { return added; } Map<IpPrefix, MasterDatabaseBinding> prefixMap = MasterDatabase .filterIncomingBindings(bindings, bindingMap::get, p -> bindingMap.remove(p) != null); if (!prefixMap.isEmpty()) { bindingMap.putAll(prefixMap); added.addAll(prefixMap.values()); } dbListener.onBindingsAdded(added); return added; }
MasterDatabaseImpl extends MasterDatabase { @Override public synchronized <T extends SxpBindingFields> List<MasterDatabaseBinding> addBindings(List<T> bindings) { List<MasterDatabaseBinding> added = new ArrayList<>(); if (bindings == null) { return added; } Map<IpPrefix, MasterDatabaseBinding> prefixMap = MasterDatabase .filterIncomingBindings(bindings, bindingMap::get, p -> bindingMap.remove(p) != null); if (!prefixMap.isEmpty()) { bindingMap.putAll(prefixMap); added.addAll(prefixMap.values()); } dbListener.onBindingsAdded(added); return added; } }
MasterDatabaseImpl extends MasterDatabase { @Override public synchronized <T extends SxpBindingFields> List<MasterDatabaseBinding> addBindings(List<T> bindings) { List<MasterDatabaseBinding> added = new ArrayList<>(); if (bindings == null) { return added; } Map<IpPrefix, MasterDatabaseBinding> prefixMap = MasterDatabase .filterIncomingBindings(bindings, bindingMap::get, p -> bindingMap.remove(p) != null); if (!prefixMap.isEmpty()) { bindingMap.putAll(prefixMap); added.addAll(prefixMap.values()); } dbListener.onBindingsAdded(added); return added; }  }
MasterDatabaseImpl extends MasterDatabase { @Override public synchronized <T extends SxpBindingFields> List<MasterDatabaseBinding> addBindings(List<T> bindings) { List<MasterDatabaseBinding> added = new ArrayList<>(); if (bindings == null) { return added; } Map<IpPrefix, MasterDatabaseBinding> prefixMap = MasterDatabase .filterIncomingBindings(bindings, bindingMap::get, p -> bindingMap.remove(p) != null); if (!prefixMap.isEmpty()) { bindingMap.putAll(prefixMap); added.addAll(prefixMap.values()); } dbListener.onBindingsAdded(added); return added; }  @Override void initDBPropagatingListener(BindingDispatcher dispatcher, SxpDomain domain); @Override synchronized List<MasterDatabaseBinding> addBindings(List<T> bindings); @Override synchronized List<MasterDatabaseBinding> getBindings(); @Override synchronized List<MasterDatabaseBinding> getBindings(OriginType origin); @Override synchronized List<MasterDatabaseBinding> deleteBindings(List<T> bindings); @Override void close(); }
MasterDatabaseImpl extends MasterDatabase { @Override public synchronized <T extends SxpBindingFields> List<MasterDatabaseBinding> addBindings(List<T> bindings) { List<MasterDatabaseBinding> added = new ArrayList<>(); if (bindings == null) { return added; } Map<IpPrefix, MasterDatabaseBinding> prefixMap = MasterDatabase .filterIncomingBindings(bindings, bindingMap::get, p -> bindingMap.remove(p) != null); if (!prefixMap.isEmpty()) { bindingMap.putAll(prefixMap); added.addAll(prefixMap.values()); } dbListener.onBindingsAdded(added); return added; }  @Override void initDBPropagatingListener(BindingDispatcher dispatcher, SxpDomain domain); @Override synchronized List<MasterDatabaseBinding> addBindings(List<T> bindings); @Override synchronized List<MasterDatabaseBinding> getBindings(); @Override synchronized List<MasterDatabaseBinding> getBindings(OriginType origin); @Override synchronized List<MasterDatabaseBinding> deleteBindings(List<T> bindings); @Override void close();  }