static void Main(string[] args) { // -help // -test // -testclient config.txt // -server config.txt // -add // -remove TODO // -list // if (args.Length >= 1 && args[0].ToLower().Equals("-test")) { bool allPassed = true; bool ok = TestMaxMem(); allPassed = allPassed && ok; if (ok) { Console.WriteLine("TestMaxMem passed"); } else { Console.WriteLine("TestMaxMem failed"); } ok = TestConsistentHash(); allPassed = allPassed && ok; if (ok) { Console.WriteLine("TestConsistentHash passed"); } else { Console.WriteLine("TestConsistentHash failed"); } ok = TestCacheRing(); allPassed = allPassed && ok; if (ok) { Console.WriteLine("TestCacheRing passed"); } else { Console.WriteLine("TestCacheRing failed"); } if (args.Length > 2 && args[1].ToLower().Equals("-config")) { CacheConfig config = CacheConfig.Load(args[2]); Console.WriteLine("Config loaded Ok"); } if (allPassed) { Console.WriteLine("All Tests Passed!"); } else { Console.WriteLine("Some Tests Failed!"); } } else if (args.Length >= 1 && args[0].ToLower().Equals("-testclient")) { if (args.Length != 2) { Console.WriteLine("Missing master hostname:port. See usage:"); Usage(); return; } // It's cheating to use anything from LoopCacheLib for client tests. // Developers can use this code as an example of how to use the API. // LoopCacheLib will *not* be referenced by client applications. CacheClient client = new CacheClient(args[1]); if (client.Test()) { Console.WriteLine("All client tests passed"); } else { Console.WriteLine("Client test failed!"); } } else if (args.Length >= 1 && args[0].ToLower().Equals("-test3")) { if (args.Length != 2) { Console.WriteLine("Missing master hostname:port. See usage:"); Usage(); return; } // It's cheating to use anything from LoopCacheLib for client tests. // Developers can use this code as an example of how to use the API. // LoopCacheLib will *not* be referenced by client applications. CacheClient client = new CacheClient(args[1]); if (client.TestThreeNodes()) { Console.WriteLine("All client tests passed"); } else { Console.WriteLine("Client test failed!"); } } else if (args.Length >= 1 && args[0].ToLower().Equals("-server")) { if (args.Length != 2) { Console.WriteLine("Expected config file location. See usage:"); Usage(); return; } // Load config and dump it to the console while in development. // We can remove this later CacheConfig config = CacheConfig.Load(args[1]); Console.WriteLine("About to start server with these settings: {0}", config.GetTrace()); CacheHelper.InitPerformanceCounters(); CacheListener listener = new CacheListener(args[1]); var task = listener.StartAsync(); Console.WriteLine("Press Enter to stop"); Console.ReadLine(); listener.Stop(); Console.WriteLine("After Stop"); bool result = task.Result; Console.WriteLine("Got result {0}", result); } else if (args.Length >= 1 && args[0].ToLower().Equals("-add")) { if (args.Length != 4) { Usage(); return; } string masterHostPortStr = args[1]; string newNodeHostPortStr = args[2]; string maxNumBytesStr = args[3]; CacheClient client = new CacheClient(masterHostPortStr); long maxNumBytes; if (!long.TryParse(maxNumBytesStr, out maxNumBytes)) { Console.WriteLine("New node maxNumBytes should be a long"); Usage(); return; } if (client.AddNode(newNodeHostPortStr, maxNumBytes)) { Console.WriteLine("New node added"); } else { Console.WriteLine("Unable to add new node, check master server logs"); } } else if (args.Length >= 1 && args[0].ToLower().Equals("-list")) { if (args.Length != 2) { Console.WriteLine("Missing master hostname:port. See usage:"); Usage(); return; } CacheClient client = new CacheClient(args[1]); client.PrintList(); } else if (args.Length >= 1 && args[0].ToLower().Equals("-testservice")) { if (args.Length != 2) { Console.WriteLine("Missing node hostname:port. See usage:"); Usage(); return; } CacheClient client = new CacheClient(args[1]); // Make sure the node is listening if (!client.Ping()) { Console.WriteLine("Unable to ping master node"); return; } if (!client.GetConfig()) { Console.WriteLine("Unable to get ring configuration"); return; } bool allTestsPassed = true; List <Guid> testObjects = new List <Guid>(); for (int i = 0; i < 1000; i++) { Guid g = Guid.NewGuid(); testObjects.Add(g); } // Put the objects Parallel.ForEach(testObjects, g => { var ok = client.PutObject(g.ToString(), g.ToString()); //Console.WriteLine("Put object {0}: {1}", // g.ToString(), ok); if (!ok) { allTestsPassed = false; } }); Console.WriteLine("Done putting objects"); if (!allTestsPassed) { Console.WriteLine("Some puts failed"); return; } // Delete the objects Parallel.ForEach(testObjects, g => { var ok = client.DeleteObject(g.ToString()); //Console.WriteLine("Deleted object {0}: {1}", // g.ToString(), ok); if (!ok) { allTestsPassed = false; } }); Console.WriteLine("Done deleting objects"); if (!allTestsPassed) { Console.WriteLine("Some deletes failed"); return; } if (allTestsPassed) { Console.WriteLine("All puts and deletes succeeded"); } } else if (args.Length >= 1 && args[0].ToLower().Equals("-reperf")) { CacheHelper.RemovePerformanceCounters(); CacheHelper.InitPerformanceCounters(); } else if (args.Length >= 1 && args[0].ToLower().Equals("-automaster")) { CacheConfig config = AutoConfigMaster(); Console.WriteLine("About to start server with these settings: {0}", config.GetTrace()); CacheHelper.InitPerformanceCounters(); CacheListener listener = new CacheListener(config); var task = listener.StartAsync(); Console.WriteLine("Press Enter to stop"); Console.ReadLine(); listener.Stop(); Console.WriteLine("After Stop"); bool result = task.Result; Console.WriteLine("Got result {0}", result); } else if (args.Length >= 1 && args[0].ToLower().Equals("-autonode")) { int portNumber = int.Parse(args[1]); CacheConfig config = AutoConfigNode(portNumber); Console.WriteLine("About to start server with these settings: {0}", config.GetTrace()); CacheHelper.InitPerformanceCounters(); CacheListener listener = new CacheListener(config); var task = listener.StartAsync(); Console.WriteLine("Press Enter to stop"); Console.ReadLine(); listener.Stop(); Console.WriteLine("After Stop"); bool result = task.Result; Console.WriteLine("Got result {0}", result); } else { Usage(); return; } Console.WriteLine("Main end"); }