From 74604f3ce583eb3f8593f879c00e02d6074b2dfb Mon Sep 17 00:00:00 2001 From: Kenichi Maehashi Date: Wed, 18 Nov 2015 20:58:34 +0900 Subject: [PATCH] add test --- .../JubatusClusterConfigurationSpec.scala | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 jubatusonyarn/jubatus-on-yarn-client/src/test/scala/us/jubat/yarn/client/JubatusClusterConfigurationSpec.scala diff --git a/jubatusonyarn/jubatus-on-yarn-client/src/test/scala/us/jubat/yarn/client/JubatusClusterConfigurationSpec.scala b/jubatusonyarn/jubatus-on-yarn-client/src/test/scala/us/jubat/yarn/client/JubatusClusterConfigurationSpec.scala new file mode 100644 index 0000000..ed5d8c6 --- /dev/null +++ b/jubatusonyarn/jubatus-on-yarn-client/src/test/scala/us/jubat/yarn/client/JubatusClusterConfigurationSpec.scala @@ -0,0 +1,139 @@ +// Jubatus: Online machine learning framework for distributed environment +// Copyright (C) 2014-2015 Preferred Networks and Nippon Telegraph and Telephone Corporation. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License version 2.1 as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +package us.jubat.yarn.client + +import us.jubat.yarn.common.LearningMachineType +import org.apache.hadoop.fs.Path + +import org.scalatest._ + +class JubatusClusterConfigurationSpec extends FlatSpec with Matchers { + "valid configuration" should "pass validation" in { + noException should be thrownBy { + new JubatusClusterConfiguration( + "valid", + LearningMachineType.Classifier, + "localhost:2181", + Some(""), + None, + new Resource(), + 2, + None, + None + ).validate() + } + } + + "invalid configuration" should "fail validation" in { + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "", /* <= ERROR: empty config */ + LearningMachineType.Classifier, + "localhost:2181", + Some(""), + None, + new Resource(), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "", /* <= ERROR: empty ZK */ + Some(""), + None, + new Resource(), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "localhost:2181", + None, /* <= ERROR */ + None, /* <= ERROR: both config file and config path are not specified */ + new Resource(), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "localhost:2181", + Some("{}"), /* <= ERROR */ + Some(new Path("file:///")), /* <= ERROR: both config file and config path are specified */ + new Resource(), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "localhost:2181", + Some("{}"), + None, + new Resource(0, 0 /* <= ERROR: invalid amount of memory */ , 1), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "localhost:2181", + Some("{}"), + None, + new Resource(0, 1, 0 /* <= ERROR: invalid number of cores */), + 2, + None, + None + ).validate() + } + + an[IllegalArgumentException] should be thrownBy { + new JubatusClusterConfiguration( + "model", + LearningMachineType.Classifier, + "localhost:2181", + Some("{}"), + None, + new Resource(), + 0, /* <= ERROR: invalid number of nodes */ + None, + None + ).validate() + } + } +}