@Override public ActiveProperties newActiveProperties() { return new ActiveProperties(propertiesAccessor); }
@org.junit.Test public void testMemoryManager() { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); int i = 0; while (fmm.get() != null) { i++; } Assert.assertEquals(i, NUM_FRAMES); Assert.assertNull(cause); }
@Override protected void doSuspend(MetadataProvider metadataProvider) throws HyracksDataException { doStop(metadataProvider, appCtx.getActiveProperties().getActiveSuspendTimeout(), TIMEOUT_UNIT); }
setState(ActivityState.STOPPING); try { doStop(metadataProvider, appCtx.getActiveProperties().getActiveStopTimeout(), TIMEOUT_UNIT); } catch (Exception e) { setState(ActivityState.STOPPED);
@org.junit.Test public void testConcurrentMemoryManager() { try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); FixedSizeAllocator[] runners = new FixedSizeAllocator[NUM_THREADS]; Thread[] threads = new Thread[NUM_THREADS]; Arrays.parallelSetAll(runners, (int i) -> new FixedSizeAllocator(fmm)); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(runners[i]); } for (int i = 0; i < threads.length; i++) { threads[i].start(); } for (int i = 0; i < threads.length; i++) { threads[i].join(); } int i = 0; for (FixedSizeAllocator allocator : runners) { i += allocator.getAllocated(); } Assert.assertEquals(NUM_FRAMES, i); } catch (Throwable th) { th.printStackTrace(); Assert.fail(th.getMessage()); } Assert.assertNull(cause); }
storageProperties = new StorageProperties(propertiesAccessor); txnProperties = new TransactionProperties(propertiesAccessor); activeProperties = new ActiveProperties(propertiesAccessor); extensionProperties = new ExtensionProperties(propertiesAccessor); replicationProperties = new ReplicationProperties(propertiesAccessor);
@org.junit.Test public void testConcurrentAcquireReleaseMemoryManager() { try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); FixedSizeGoodAllocator[] runners = new FixedSizeGoodAllocator[NUM_THREADS]; Thread[] threads = new Thread[NUM_THREADS]; Arrays.parallelSetAll(runners, (int i) -> new FixedSizeGoodAllocator(fmm)); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(runners[i]); } for (int i = 0; i < threads.length; i++) { threads[i].start(); } for (int i = 0; i < threads.length; i++) { threads[i].join(); } int i = 0; for (FixedSizeGoodAllocator allocator : runners) { i += allocator.getAllocated(); } Assert.assertEquals(NUM_FRAMES, i); } catch (Throwable th) { th.printStackTrace(); Assert.fail(th.getMessage()); } Assert.assertNull(cause); }
@org.junit.Test public void testAcquireReleaseMemoryManager() throws HyracksDataException { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); Random random = new Random(); ArrayDeque<ByteBuffer> stack = new ArrayDeque<>();
try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); Random random = new Random(); ArrayDeque<ByteBuffer> stack = new ArrayDeque<>();
try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); Random random = new Random(); int i = 0;
try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); VarSizeGoodAllocator[] runners = new VarSizeGoodAllocator[NUM_THREADS]; Thread[] threads = new Thread[NUM_THREADS];
@org.junit.Test public void testFixedSizeSubscribtion() { try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); int i = 0; ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE); LinkedBlockingDeque<ByteBuffer> buffers = new LinkedBlockingDeque<>(); FrameAction frameAction = new FrameAction(); frameAction.setFrame(buffer); while (!fmm.subscribe(frameAction)) { buffers.put(frameAction.retrieve()); i++; } // One subscriber. // Check that all frames have been consumed Assert.assertEquals(i, NUM_FRAMES); // Release a frame (That will be handed out to the subscriber) fmm.release(buffers.take()); // Check that all frames have been consumed (since the released frame have been handed to the consumer) Assert.assertEquals(0, fmm.remaining()); } catch (Throwable th) { th.printStackTrace(); Assert.fail(th.getMessage()); } finally { Assert.assertNull(cause); } }
try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
try { ActiveProperties afp = Mockito.mock(ActiveProperties.class); Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET); ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE); int i = 0; ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE);
isShuttingdown = false; activeManager = new ActiveManager(threadExecutor, getServiceContext().getNodeId(), activeProperties.getMemoryComponentGlobalBudget(), compilerProperties.getFrameSize(), this.ncServiceContext);