| /*=============================================================================# |
| # Copyright (c) 2019 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.rj.servi.pool; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertTrue; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.NoSuchElementException; |
| |
| import javax.management.OperationsException; |
| import javax.security.auth.login.LoginException; |
| |
| import org.junit.After; |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runners.model.MultipleFailureException; |
| |
| import org.eclipse.statet.jcommons.rmi.RMIRegistry; |
| import org.eclipse.statet.jcommons.rmi.RMIRegistryManager; |
| import org.eclipse.statet.jcommons.status.NullProgressMonitor; |
| import org.eclipse.statet.jcommons.status.Status; |
| import org.eclipse.statet.jcommons.status.StatusException; |
| |
| import org.eclipse.statet.rj.RjException; |
| import org.eclipse.statet.rj.data.RDataUtils; |
| import org.eclipse.statet.rj.data.UnexpectedRDataException; |
| import org.eclipse.statet.rj.server.util.RJContext; |
| import org.eclipse.statet.rj.servi.RServi; |
| import org.eclipse.statet.rj.servi.RServiUtils; |
| import org.eclipse.statet.rj.servi.node.RServiImpl; |
| import org.eclipse.statet.rj.servi.node.RServiNodeConfig; |
| import org.eclipse.statet.rj.servi.node.RServiNodeFactory; |
| import org.eclipse.statet.rj.servi.node.RServiNodeManager; |
| |
| |
| public class LocalNodeTest extends AbstractServiTest { |
| |
| |
| private RServiNodeManager localR; |
| |
| |
| public LocalNodeTest() { |
| } |
| |
| |
| @Before |
| public void initNode() throws RjException, StatusException { |
| final RJContext context= ServiTests.getRJContext(); |
| final RMIRegistry rmiRegistry= RMIRegistryManager.INSTANCE.getEmbeddedPrivateRegistry( |
| new NullProgressMonitor() ); |
| |
| final RServiNodeFactory nodeFactory= RServiImpl.createLocalNodeFactory( |
| "LocalNodeTest", context ); |
| nodeFactory.setRegistry(rmiRegistry); |
| nodeFactory.setConfig(new RServiNodeConfig()); |
| |
| this.localR= RServiImpl.createNodeManager("LocalNodeTest", rmiRegistry, nodeFactory); |
| } |
| |
| @After |
| public void dispose() throws Exception { |
| final List<Throwable> exceptions= new ArrayList<>(); |
| disposeServis(exceptions); |
| try { |
| if (this.localR != null) { |
| this.localR.stop(); |
| } |
| } |
| catch (final Exception e) { |
| exceptions.add(e); |
| } |
| finally { |
| this.localR= null; |
| } |
| |
| MultipleFailureException.assertEmpty(exceptions); |
| } |
| |
| private RServi getServi(final String id) throws NoSuchElementException, LoginException, StatusException { |
| final RServi servi= RServiUtils.getRServi(this.localR, id); |
| onServiGet(servi); |
| return servi; |
| } |
| |
| |
| @Test |
| public void test1() throws RjException, OperationsException, |
| NoSuchElementException, LoginException, StatusException, UnexpectedRDataException { |
| this.localR.start(); |
| |
| final RServi servi1= getServi("test1"); |
| assertNodeOperative(servi1); |
| closeServi(servi1); |
| } |
| |
| @Test |
| public void closed() throws RjException, OperationsException, |
| NoSuchElementException, LoginException, StatusException, UnexpectedRDataException { |
| this.localR.start(); |
| |
| final RServi servi1= getServi("test1"); |
| assertNodeOperative(servi1); |
| assertEquals(false, servi1.isClosed()); |
| closeServi(servi1); |
| |
| assertEquals(true, servi1.isClosed()); |
| try { |
| assertNodeOperative(servi1); |
| throw new AssertionError("not closed"); |
| } |
| catch (final StatusException e) { |
| final Status eStatus= e.getStatus(); |
| assertEquals(Status.ERROR, eStatus.getSeverity()); |
| assertTrue(e.getMessage().contains("closed")); |
| } |
| } |
| |
| @Test |
| public void cleanup() throws RjException, OperationsException, |
| NoSuchElementException, LoginException, StatusException, UnexpectedRDataException { |
| this.localR.start(); |
| |
| final RServi servi1= getServi("test1"); |
| |
| servi1.evalVoid("x <- 123L", null); |
| servi1.evalVoid(".x <- 123L", null); |
| assertEquals(true, RDataUtils.checkSingleLogiValue(servi1.evalData("exists(\"x\")", null))); |
| assertEquals(true, RDataUtils.checkSingleLogiValue(servi1.evalData("exists(\".x\")", null))); |
| |
| closeServi(servi1); |
| |
| final RServi servi2= getServi("test1"); |
| assertEquals(false, RDataUtils.checkSingleLogiValue(servi2.evalData("exists(\"x\")", null))); |
| assertEquals(false, RDataUtils.checkSingleLogiValue(servi2.evalData("exists(\".x\")", null))); |
| |
| closeServi(servi2); |
| } |
| |
| } |