public void setName(String endpointName) { this.endpointName = endpointName; if (enableMBeanStats) { if (endpointName == null || "".equals(endpointName.trim())) { //we skip stat collection for endpoints with no defined name log.warn("Endpoint Name not found. Skipped JMX statistics collection for this endpoint"); return; } metricsMBean = new EndpointView(endpointName, this); MBeanRegistrar.getInstance().registerMBean(metricsMBean, "Endpoint", endpointName); } }
public void setName(String endpointName) { this.endpointName = endpointName; if (enableMBeanStats) { /*if (endpointName != null && !"".equals(endpointName.trim())){ //we skip stat collection for endpoints with no defined name log.warn("Endpoint Name not found. Skipped JMX statistics collection for this endpoint"); return; }*/ metricsMBean = new EndpointView(endpointName, this); // if(metricsMBean != null) { // metricsMBean.destroy(); // } MBeanRegistrar.getInstance().registerMBean(metricsMBean, "Endpoint", endpointName); } }
/** * Method to create an endpoint view with a mocked endpoint with the specified number of children. * * @param numberOfChildren the child endpoints inside the endpoint attached to the end point view. If * specified as 0, the children list will be null * @return the created end point view */ private EndpointView createMockEndPointView(int numberOfChildren) { AbstractEndpoint abstractEndpoint = createMockEndPoint(numberOfChildren); return new EndpointView("endpoint", abstractEndpoint); }
/** * Asserts if the the endpoint view correctly returns the number of child endpoints in the ready state. * * @throws Exception if an error occurs while accessing child endpoints */ public void testGetReadyChildren() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(3); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().readyToSend()).thenReturn(true); Assert.assertEquals("Incorrect ready children count", 1, endpointView.getReadyChildren()); endpointView = createMockEndPointView(0); Assert.assertEquals("Ready children count should be empty", 0, endpointView.getReadyChildren()); }
/** * Tests if the endpoint view correctly returns the active state with and without the presence of children * endpoints. The endpoint should be inactive if and only if all child endpoints are inactive. * * @throws Exception if an error occurs while accessing the active children of the endpoint view */ public void testIsActive() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(3); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(2).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Assert.assertTrue("Endpoint view is not active with active child endpoint", endpointView.isActive()); endpoint = createMockEndPoint(0); EndpointContext endpointContext = Mockito.mock(EndpointContext.class); Mockito.when(endpoint.getContext()).thenReturn(endpointContext); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Assert.assertTrue("Endpoint view is not active", endpointView.isActive()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Assert.assertFalse("Endpoint is active", endpointView.isActive()); }
/** * Tests if the endpoint view correctly returns the suspended state with and without the presence of children * endpoints. The endpoint view should be suspended if and only if all child endpoints are suspended. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsSuspended() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertFalse("Endpoint view is suspended with active child endpoints", endpointView.isSuspended()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertTrue("Endpoint view is not suspended with all child endpoints being suspended", endpointView.isSuspended()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertTrue("Endpoint view is not suspended", endpointView.isSuspended()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(false); Assert.assertFalse("Endpoint view is suspended", endpointView.isSuspended()); }
/** * Tests if the endpoint view correctly returns the switched off state with and without the presence of children * endpoints. The endpoint view should be switched if and only if all child endpoints are switched off. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsSwitchedOff() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertFalse("Endpoint view switched off with active child endpoints", endpointView.isSwitchedOff()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertTrue("Endpoint view is not switched off with all child endpoints being switched off", endpointView.isSwitchedOff()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertTrue("Endpoint view is not switched off", endpointView.isSwitchedOff()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_OFF)).thenReturn(false); Assert.assertFalse("Endpoint view is swtiched off", endpointView.isSwitchedOff()); }
/** * Tests if the endpoint view correctly returns the timed out state with and without the presence of children * endpoints. The endpoint view should be timed out if and only if all child endpoints are timed out. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsTimedout() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertFalse("Endpoint view is timed out with active child endpoints", endpointView.isTimedout()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertTrue("Endpoint view is not timed out with all child endpoints being timed out", endpointView.isTimedout()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertTrue("Endpoint view is not timed out", endpointView.isTimedout()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(false); Assert.assertFalse("Endpoint view is timed out", endpointView.isTimedout()); }
/** * Asserts if the the endpoint view correctly returns the number of active child endpoints included in the * endpoint associated with the view. * * @throws Exception if an error occurs while accessing child endpoints */ public void testGetActiveChildren() throws Exception { //Assert with children AbstractEndpoint endpoint = createMockEndPoint(5); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(2).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(3).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(4).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); EndpointView endpointView = new EndpointView("endpoint", endpoint); Assert.assertEquals("Incorrect active children count", 3, endpointView.getActiveChildren()); //Assert when endpoint has no children EndpointView endpointViewWithoutChildren = createMockEndPointView(0); Assert.assertEquals("Incorrect active children count", 0, endpointViewWithoutChildren.getActiveChildren()); }
/** * Performs the following operation to test destroy of an endpoint view. * 1. Increment suspension and timeout counts * 2. Call method destroy of endpoint view * 3. Assert counts to be reset */ public void testDestroy() { EndpointView endpointView = new EndpointView("endpoint", null); endpointView.incrementSuspensions(); endpointView.incrementTimeouts(); endpointView.destroy(); Assert.assertEquals("Last minute suspension count is not reset", 0, endpointView.getLastMinuteEndpointSuspensions()); Assert.assertEquals("Last 5 minute count is not reset", 0, endpointView.getLast5MinuteEndpointSuspensions()); Assert.assertEquals("Last 15 minute count is not reset", 0, endpointView.getLast15MinuteEndpointSuspensions()); Assert.assertEquals("Last minute timeout count is not reset", 0, endpointView.getLastMinuteEndpointTimeouts()); Assert.assertEquals("Last 5 minute timeout count is not reset", 0, endpointView.getLast5MinuteEndpointTimeouts()); Assert.assertEquals("Last 15 minute count is not reset", 0, endpointView.getLast15MinuteEndpointTimeouts()); }
/** * Creates a basic EndpointView with a given number of children added to the endpoint. * * @param numberOfChildren the child endpoints inside the endpoint attached to the end point view. If * specified as 0, the children list will be null * @return the created end point view */ private EndpointView createEndPointView(int numberOfChildren) { AbstractEndpoint endpoint = new AddressEndpoint(); MessageContext synCtx = new TestMessageContext(); synCtx.setConfiguration(new SynapseConfiguration()); SynapseEnvironment environment = new Axis2SynapseEnvironment( new ConfigurationContext(new AxisConfiguration()), synCtx.getConfiguration()); if (numberOfChildren > 0) { List<Endpoint> children = new ArrayList<>(numberOfChildren); for (int i = 0; i < numberOfChildren; i++) { AbstractEndpoint child = new AddressEndpoint(); child.init(environment); child.setEnableMBeanStats(true); child.setName("endpoint" + i); children.add(child); } endpoint.setChildren(children); } endpoint.init(environment); return new EndpointView("endpoint", endpoint); }