public static VdsNetworkInterface setUpStatistics(VdsNetworkInterface entity, Guid id) { VdsNetworkStatistics statistics = new VdsNetworkStatistics(); statistics.setId(null); statistics.setReceiveDropRate(1D); statistics.setReceiveRate(2D); statistics.setTransmitDropRate(3D); statistics.setTransmitRate(4D); statistics.setReceivedBytes(5L); statistics.setTransmittedBytes(6L); statistics.setVdsId(id); statistics.setStatus(null); entity.setStatistics(statistics); return entity; }
protected VdsNetworkInterface setUpStatisticalExpectations() { VdsNetworkStatistics stats = mock(VdsNetworkStatistics.class); VdsNetworkInterface entity = mock(VdsNetworkInterface.class); when(entity.getSpeed()).thenReturn(SPEED); when(entity.getStatistics()).thenReturn(stats); when(entity.getId()).thenReturn(NIC_ID); when(stats.getReceiveRate()).thenReturn(RECEIVE_RATE); when(stats.getTransmitRate()).thenReturn(TRANSMIT_RATE); when(stats.getReceiveDropRate()).thenReturn(RECEIVE_DROP_RATE); when(stats.getTransmitDropRate()).thenReturn(TRANSMIT_DROP_RATE); when(stats.getReceivedBytes()).thenReturn(RECEIVED_BYTES); when(stats.getTransmittedBytes()).thenReturn(TRANSMITTED_BYTES); List<VdsNetworkInterface> ifaces = new ArrayList<>(); ifaces.add(entity); setUpEntityQueryExpectations(QueryType.GetVdsInterfacesByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { PARENT_GUID }, ifaces); return entity; }
@Test public void testMasshUpdateStatisticsForVds() { List<VdsNetworkInterface> interfaces = dao.getAllInterfacesForVds(VDS_ID); List<VdsNetworkStatistics> statistics = new ArrayList<>(interfaces.size()); for (VdsNetworkInterface iface : interfaces) { VdsNetworkStatistics stats = iface.getStatistics(); stats.setReceiveDropRate(RandomUtils.instance().nextInt() * 1.0); stats.setStatus(RandomUtils.instance().nextEnum(InterfaceStatus.class)); statistics.add(stats); } dao.massUpdateStatisticsForVds(statistics); List<VdsNetworkInterface> after = dao.getAllInterfacesForVds(VDS_ID); for (VdsNetworkInterface iface : after) { boolean found = false; for (VdsNetworkStatistics stats : statistics) { if (iface.getId().equals(stats.getId())) { found = true; assertEquals(stats.getReceiveDropRate(), iface.getStatistics().getReceiveDropRate()); assertEquals(stats.getStatus(), iface.getStatistics().getStatus()); } } assertTrue(found); } }
@Override protected VdsNetworkStatistics createEntity() { return new VdsNetworkStatistics(); } }
@Override public InterfaceStatus getStatus() { return getOriginalIface().getStatistics().getStatus(); }
/** * Sets the related VDS id. * * @param vdsId * the id */ public void setVdsId(Guid vdsId) { this.vdsId = vdsId; this.statistics.setVdsId(vdsId); }
private HostInterface hostInterfaceFromNic(VdsNetworkInterface nic) { HostInterface hi = new HostInterface(); hi.setInterface(nic); hi.setName(nic.getName()); hi.setIpv4Address(nic.getIpv4Address()); hi.setIpv6Address(nic.getIpv6Address()); hi.setMAC(nic.getMacAddress()); hi.setSpeed(nic.getSpeed()); hi.setRxRate(nic.getStatistics().getReceiveRate()); hi.setRxTotal(nic.getStatistics().getReceivedBytes()); hi.setRxDrop(nic.getStatistics().getReceiveDropRate()); hi.setTxRate(nic.getStatistics().getTransmitRate()); hi.setTxTotal(nic.getStatistics().getTransmittedBytes()); hi.setTxDrop(nic.getStatistics().getTransmitDropRate()); hi.setStatus(nic.getStatistics().getStatus()); hi.getPropertyChangedEvent().addListener(this); return hi; }
public VdsNetworkInterface() { super(new VdsNetworkStatistics(), VdsInterfaceType.NONE.getValue()); }
@Override public VdsNetworkStatistics mapRow(ResultSet rs, int rowNum) throws SQLException { VdsNetworkStatistics entity = super.mapRow(rs, rowNum); entity.setVdsId(getGuidDefaultEmpty(rs, "vds_id")); return entity; }
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); existingVdsInterface = dao.get(FixturesTool.VDS_NETWORK_INTERFACE); newQos = new HostNetworkQos(); newQos.setOutAverageLinkshare(30); newQos.setOutAverageUpperlimit(30); newQos.setOutAverageRealtime(30); newVdsInterface = new VdsNetworkInterface(); newVdsInterface.setStatistics(new VdsNetworkStatistics()); newVdsInterface.setId(Guid.newGuid()); newVdsInterface.setName("eth77"); newVdsInterface.setNetworkName("enginet"); newVdsInterface.setSpeed(1000); newVdsInterface.setType(3); newVdsInterface.setMacAddress("01:C0:81:21:71:17"); newVdsInterface.setIpv4BootProtocol(Ipv4BootProtocol.STATIC_IP); newVdsInterface.setIpv4Address("192.168.122.177"); newVdsInterface.setIpv4Subnet("255.255.255.0"); newVdsInterface.setIpv4Gateway("192.168.122.1"); newVdsInterface.setIpv6BootProtocol(Ipv6BootProtocol.AUTOCONF); newVdsInterface.setIpv6Address("ipv6 address"); newVdsInterface.setIpv6Prefix(666); newVdsInterface.setIpv6Gateway("ipv6 gateway"); newVdsInterface.setMtu(1500); newVdsInterface.setQos(newQos); newVdsStatistics = newVdsInterface.getStatistics(); }