public void testBasics() { MemoryManager mgr = new MemoryManager(configuredPoolSize); NullCallback callback = new NullCallback(); long poolSize = mgr.getTotalMemoryPool(); Assert.Equal(configuredPoolSize, poolSize); Assert.Equal(1.0, mgr.getAllocationScale(), 5); mgr.addWriter("p1", 1000, callback); Assert.Equal(1.0, mgr.getAllocationScale(), 5); mgr.addWriter("p1", poolSize / 2, callback); Assert.Equal(1.0, mgr.getAllocationScale(), 5); mgr.addWriter("p2", poolSize / 2, callback); Assert.Equal(1.0, mgr.getAllocationScale(), 5); mgr.addWriter("p3", poolSize / 2, callback); Assert.Equal(0.6666667, mgr.getAllocationScale(), 5); mgr.addWriter("p4", poolSize / 2, callback); Assert.Equal(0.5, mgr.getAllocationScale(), 6); mgr.addWriter("p4", 3 * poolSize / 2, callback); Assert.Equal(0.3333333, mgr.getAllocationScale(), 6); mgr.removeWriter("p1"); mgr.removeWriter("p2"); Assert.Equal(0.5, mgr.getAllocationScale(), 5); mgr.removeWriter("p4"); Assert.Equal(1.0, mgr.getAllocationScale(), 5); }
public void testCallback() { Configuration conf = new Configuration(); MemoryManager mgr = new MemoryManager(configuredPoolSize); long pool = mgr.getTotalMemoryPool(); LoggingCallback[] calls = new LoggingCallback[20]; for (int i = 0; i < calls.Length; ++i) { calls[i] = new LoggingCallback(); mgr.addWriter(i.ToString(), pool / 4, calls[i]); } // add enough rows to get the memory manager to check the limits for (int i = 0; i < 10000; ++i) { mgr.addedRow(1); } for (int call = 0; call < calls.Length; ++call) { Assert.Equal(2, calls[call].LogLength); foreach (double argument in calls[call].Log) { Assert.Equal(0.2, argument, ERROR); } } }
public void testConfig() { Configuration conf = new Configuration(); conf.set("hive.exec.orc.memory.pool", "0.9"); MemoryManager mgr = new MemoryManager(conf); long mem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax(); System.Console.WriteLine("Memory = " + mem); long pool = mgr.getTotalMemoryPool(); Assert.True("Pool too small: " + pool, mem * 0.899 < pool); Assert.True("Pool too big: " + pool, pool < mem * 0.901); }