@Test public void testAddPhysicalHost() throws Exception { final PhysicalHost physicalHost = mock(PhysicalHost.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); PhysicalHostKey physicalHostKey = mock(PhysicalHostKey.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class; Method method = class1.getDeclaredMethod("addPhysicalHost",new Class[]{PhysicalHost.class}); method.setAccessible(true); when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(physicalHost.getKey()).thenReturn(physicalHostKey); when(writeTransaction.submit()).thenReturn(checkedFuture); method.invoke(dataBrokerAdapter, physicalHost); verify(dataBroker).newWriteOnlyTransaction(); verify(physicalHost).getKey(); verify(writeTransaction).submit(); }
protected void addPhysicalHost(final PhysicalHost physicalHost) { try { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final InstanceIdentifier<PhysicalHost> instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); } @Override public void onSuccess(Void result) { log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); } }); } catch (Exception e) { log.error("Exception:",e); } }
DataBrokerAdapter { protected void addPhysicalHost(final PhysicalHost physicalHost) { try { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final InstanceIdentifier<PhysicalHost> instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); } @Override public void onSuccess(Void result) { log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); } }); } catch (Exception e) { log.error("Exception:",e); } } }
DataBrokerAdapter { protected void addPhysicalHost(final PhysicalHost physicalHost) { try { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final InstanceIdentifier<PhysicalHost> instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); } @Override public void onSuccess(Void result) { log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); } }); } catch (Exception e) { log.error("Exception:",e); } } DataBrokerAdapter(DataBroker dataBroker); }
DataBrokerAdapter { protected void addPhysicalHost(final PhysicalHost physicalHost) { try { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final InstanceIdentifier<PhysicalHost> instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); } @Override public void onSuccess(Void result) { log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); } }); } catch (Exception e) { log.error("Exception:",e); } } DataBrokerAdapter(DataBroker dataBroker);  }
DataBrokerAdapter { protected void addPhysicalHost(final PhysicalHost physicalHost) { try { WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final InstanceIdentifier<PhysicalHost> instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); } @Override public void onSuccess(Void result) { log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); } }); } catch (Exception e) { log.error("Exception:",e); } } DataBrokerAdapter(DataBroker dataBroker);   }