public async void CleanupExpiredLease_Expect_NoExpiredLeases() { var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var expiredLease = ModelFakes.GetFakeLease(); expiredLease.Expiration = DateTime.UtcNow.AddMinutes(-2); var validLease = ModelFakes.GetFakeLease(); validLease.IpAddress = "10.10.10.11"; validLease.PhysicalAddress = "332211556677"; validLease.HostName = "boot22.local"; await leaseRepo.Insert(expiredLease).ConfigureAwait(false); await leaseRepo.Insert(validLease).ConfigureAwait(false); await leaseManager.CleanExpiredLeases(); var expiredEntity = await leaseRepo.GetByIpAddress(expiredLease.IpAddress).ConfigureAwait(false); var validEntity = await leaseRepo.GetByIpAddress(validLease.IpAddress).ConfigureAwait(false); Assert.Null(expiredEntity); Assert.NotNull(validEntity); }
/// <summary> /// Add new lease to database /// </summary> /// <param name="selectedSlipId">slip that was selected</param> private void addNewLease(int selectedSlipId) { int slipID = Convert.ToInt32(selectedSlipId); int custID = Convert.ToInt32(Session["custID"]); LeaseManager.Add(slipID, custID); }
private static void LeaseTest() { LeaseManager leaseManager = new LeaseManager(new EfLeaseDal()); foreach (var lease in leaseManager.GetAll().Data) { System.Console.WriteLine(lease.LeaseDate); } }
public async void NoLeases_Expect_NextLeaseToBeStartIpAddress() { var config = DhcpFakes.FakeDhcpConfiguration(); var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(config, leaseRepo); var nextLease = await leaseManager.GetNextLease().ConfigureAwait(false); Assert.Equal(config.StartIpAddress, nextLease); }
protected void uxRelatedSlipGrid_SelectedIndexChanged(object sender, EventArgs e) { int slipId = Convert.ToInt32(uxRelatedSlipGrid.SelectedRow.Cells[0].Text); int customerId = Convert.ToInt32(Session["customer"]); LeaseManager.addLease(customerId, slipId);//add new lease //refresh 2 grids uxRelatedSlipGrid.DataBind(); uxRelatedSlipGrid.SelectedIndex = -1; uxGvHistory.DataBind(); }
public async void KeepLeaseWithNoMatch_Expect_RequestAccepted() { var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var ipAddress = IPAddress.Parse("10.10.10.10"); var hostName = "myserver.local"; var physicalAddress = PhysicalAddress.Parse("000000000000"); bool keepLeaseResponse = await leaseManager.KeepLeaseRequest(ipAddress, physicalAddress, hostName).ConfigureAwait(false); Assert.True(keepLeaseResponse); }
public async void InsertLease_Expect_NextLeaseToBeNextIpAddress() { var config = DhcpFakes.FakeDhcpConfiguration(); var nextIp = config.StartIpAddress.ToNextIpAddress(); var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var lease = ModelFakes.GetFakeLease(config.StartIpAddress.ToString()); await leaseRepo.Insert(lease).ConfigureAwait(false); var nextLease = await leaseManager.GetNextLease(); Assert.Equal(nextIp, nextLease); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack || Session["leaseslip"] is null) { //instantiate List selectedSlipList = new List <Slip>(); //adding new session Session.Add("leaseslip", selectedSlipList); } DockSelector.DockSelect += DockSelector_DockSelect; //displays customer's previously leased items uxPreviouslyLeased.DataSource = LeaseManager.Find(Convert.ToInt32(Session["custID"])); uxPreviouslyLeased.DataBind(); }
public async void KeepLeaseWithMatch_WrongMAC_Expect_RequestRejected() { var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var ipAddress = IPAddress.Parse("10.10.10.10"); var hostName = "myserver.local"; var physicalAddress = PhysicalAddress.Parse("000000000000"); var physicalAddress2 = PhysicalAddress.Parse("999999999999"); await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false); var keepLeaseResponse = await leaseManager.KeepLeaseRequest(ipAddress, physicalAddress2, hostName).ConfigureAwait(false); Assert.False(keepLeaseResponse); }
static void Main(string[] args) { //Data Transformation Object-DTO //CarTest(); //LeaseTest(); //UserTest(); //LeaseGetByIdTest(); LeaseManager leaseManager = new LeaseManager(new EfLeaseDal()); System.Console.WriteLine(leaseManager.Add(new Lease { CarId = 1, CustomerId = 2, LeaseDate = DateTime.Now }).Message); }
public async void RemoveLease_Expect_NoLeaseInDb() { var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var ipAddress = IPAddress.Parse("10.10.10.10"); var hostName = "myserver.local"; var physicalAddress = PhysicalAddress.Parse("000000000000"); await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false); await leaseManager.RemoveLease(ipAddress).ConfigureAwait(false); var entity = await leaseRepo.GetByIpAddress(ipAddress).ConfigureAwait(false); Assert.Null(entity); }
public async void AddLease_Expect_LeaseInDb() { var leaseRepo = new LeaseRepo(DbConfig); var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo); var ipAddress = IPAddress.Parse("10.10.10.10"); var hostName = "myserver.local"; var physicalAddress = PhysicalAddress.Parse("000000000000"); await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false); var entity = await leaseRepo.GetByIpAddress(ipAddress).ConfigureAwait(false); Assert.Equal(ipAddress.ToString(), entity.IpAddress); Assert.Equal(physicalAddress.ToString(), entity.PhysicalAddress); Assert.Equal(hostName, entity.HostName); }
public virtual void TestBlockSynchronization() { int OrgFileSize = 3000; Configuration conf = new HdfsConfiguration(); conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, BlockSize); cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(5).Build(); cluster.WaitActive(); //create a file DistributedFileSystem dfs = cluster.GetFileSystem(); string filestr = "/foo"; Path filepath = new Path(filestr); DFSTestUtil.CreateFile(dfs, filepath, OrgFileSize, ReplicationNum, 0L); NUnit.Framework.Assert.IsTrue(dfs.Exists(filepath)); DFSTestUtil.WaitReplication(dfs, filepath, ReplicationNum); //get block info for the last block LocatedBlock locatedblock = TestInterDatanodeProtocol.GetLastLocatedBlock(dfs.dfs .GetNamenode(), filestr); DatanodeInfo[] datanodeinfos = locatedblock.GetLocations(); NUnit.Framework.Assert.AreEqual(ReplicationNum, datanodeinfos.Length); //connect to data nodes DataNode[] datanodes = new DataNode[ReplicationNum]; for (int i = 0; i < ReplicationNum; i++) { datanodes[i] = cluster.GetDataNode(datanodeinfos[i].GetIpcPort()); NUnit.Framework.Assert.IsTrue(datanodes[i] != null); } //verify Block Info ExtendedBlock lastblock = locatedblock.GetBlock(); DataNode.Log.Info("newblocks=" + lastblock); for (int i_1 = 0; i_1 < ReplicationNum; i_1++) { CheckMetaInfo(lastblock, datanodes[i_1]); } DataNode.Log.Info("dfs.dfs.clientName=" + dfs.dfs.clientName); cluster.GetNameNodeRpc().Append(filestr, dfs.dfs.clientName, new EnumSetWritable < CreateFlag>(EnumSet.Of(CreateFlag.Append))); // expire lease to trigger block recovery. WaitLeaseRecovery(cluster); Block[] updatedmetainfo = new Block[ReplicationNum]; long oldSize = lastblock.GetNumBytes(); lastblock = TestInterDatanodeProtocol.GetLastLocatedBlock(dfs.dfs.GetNamenode(), filestr).GetBlock(); long currentGS = lastblock.GetGenerationStamp(); for (int i_2 = 0; i_2 < ReplicationNum; i_2++) { updatedmetainfo[i_2] = DataNodeTestUtils.GetFSDataset(datanodes[i_2]).GetStoredBlock (lastblock.GetBlockPoolId(), lastblock.GetBlockId()); NUnit.Framework.Assert.AreEqual(lastblock.GetBlockId(), updatedmetainfo[i_2].GetBlockId ()); NUnit.Framework.Assert.AreEqual(oldSize, updatedmetainfo[i_2].GetNumBytes()); NUnit.Framework.Assert.AreEqual(currentGS, updatedmetainfo[i_2].GetGenerationStamp ()); } // verify that lease recovery does not occur when namenode is in safemode System.Console.Out.WriteLine("Testing that lease recovery cannot happen during safemode." ); filestr = "/foo.safemode"; filepath = new Path(filestr); dfs.Create(filepath, (short)1); cluster.GetNameNodeRpc().SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter, false); NUnit.Framework.Assert.IsTrue(dfs.dfs.Exists(filestr)); DFSTestUtil.WaitReplication(dfs, filepath, (short)1); WaitLeaseRecovery(cluster); // verify that we still cannot recover the lease LeaseManager lm = NameNodeAdapter.GetLeaseManager(cluster.GetNamesystem()); NUnit.Framework.Assert.IsTrue("Found " + lm.CountLease() + " lease, expected 1", lm.CountLease() == 1); cluster.GetNameNodeRpc().SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave, false); }
private void LoadManagers() { Debug.Assert(CheckIPIsUsed != null, "DhcpServer --LoadManagers-- CheckIPIsUsed = null"); log.Info("Loading managers from context..."); V6NaAddrBindingManager v6NaAddrBindingMgr = new V6NaAddrBindingManagerImpl(); v6NaAddrBindingMgr.CheckIPIsUsed = CheckIPIsUsed; try { log.Info("Initializing V6 NA Address Binding Manager"); v6NaAddrBindingMgr.Init(); _dhcpServerConfig.SetNaAddrBindingMgr(v6NaAddrBindingMgr); } catch (Exception ex) { log.Error("Failed initialize V6 NA Address Binding Manager"); throw ex; } V6TaAddrBindingManager v6TaAddrBindingMgr = new V6TaAddrBindingManagerImpl(); v6TaAddrBindingMgr.CheckIPIsUsed = CheckIPIsUsed; try { log.Info("Initializing V6 TA Address Binding Manager"); v6TaAddrBindingMgr.Init(); _dhcpServerConfig.SetTaAddrBindingMgr(v6TaAddrBindingMgr); } catch (Exception ex) { log.Error("Failed initialize V6 TA Address Binding Manager"); throw ex; } V6PrefixBindingManager v6PrefixBindingMgr = new V6PrefixBindingManagerImpl(); v6PrefixBindingMgr.CheckIPIsUsed = CheckIPIsUsed; try { log.Info("Initializing V6 Prefix Binding Manager"); v6PrefixBindingMgr.Init(); _dhcpServerConfig.SetPrefixBindingMgr(v6PrefixBindingMgr); } catch (Exception ex) { log.Error("Failed initialize V6 Prefix Binding Manager"); throw ex; } V4AddrBindingManager v4AddrBindingMgr = new V4AddrBindingManagerImpl(); v4AddrBindingMgr.CheckIPIsUsed = CheckIPIsUsed; try { log.Info("Initializing V4 Address Binding Manager"); v4AddrBindingMgr.Init(); _dhcpServerConfig.SetV4AddrBindingMgr(v4AddrBindingMgr); } catch (Exception ex) { log.Error("Failed initialize V4 Address Binding Manager"); throw ex; } IaManager iaMgr = new LeaseManager(); _dhcpServerConfig.SetIaMgr(iaMgr); log.Info("Managers loaded."); }
public string AddLease(DateTime startDate, DateTime endDate, int slipID, int customerID, int leaseTypeID) { return(LeaseManager.AddLease(startDate, endDate, slipID, customerID, leaseTypeID)); }