001/* 002 * $Id$ 003 */ 004 005package edu.jas.application; 006 007 008import java.io.ByteArrayOutputStream; 009import java.io.PrintStream; 010import java.util.concurrent.ExecutorService; 011 012import edu.jas.kern.ComputerThreads; 013 014import junit.framework.Test; 015import junit.framework.TestCase; 016import junit.framework.TestSuite; 017 018 019/** 020 * CLI tests with JUnit for GBs. 021 * @author Heinz Kredel 022 */ 023 024public class RunGBTest extends TestCase { 025 026 027 /** 028 * main. 029 */ 030 public static void main(String[] args) { 031 junit.textui.TestRunner.run(suite()); 032 } 033 034 035 /** 036 * Constructs a <CODE>RunGBTest</CODE> object. 037 * @param name String. 038 */ 039 public RunGBTest(String name) { 040 super(name); 041 } 042 043 044 /** 045 */ 046 public static Test suite() { 047 TestSuite suite = new TestSuite(RunGBTest.class); 048 return suite; 049 } 050 051 052 @Override 053 protected void setUp() { 054 } 055 056 057 @Override 058 protected void tearDown() { 059 ComputerThreads.terminate(); 060 } 061 062 063 /** 064 * Test sequential GB. 065 */ 066 public void testSequentialGB() { 067 RunGB cli = new RunGB(); 068 PrintStream ps = System.out; 069 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 070 PrintStream ss = new PrintStream(bs); 071 try { 072 System.setOut(ss); 073 cli.main(new String[] { "seq", "examples/trinks7.jas", "check" }); 074 } finally { 075 System.setOut(ps); 076 } 077 String sto = bs.toString(); 078 //System.out.println(sto); 079 assertTrue("sequential", sto.contains("sequential")); 080 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 081 assertTrue("check isGB = true", sto.contains("check isGB = true")); 082 } 083 084 085 /** 086 * Test sequential GB plus. 087 */ 088 public void testSequentialGBplus() { 089 RunGB cli = new RunGB(); 090 PrintStream ps = System.out; 091 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 092 PrintStream ss = new PrintStream(bs); 093 try { 094 System.setOut(ss); 095 cli.main(new String[] { "seq+", "examples/trinks7.jas", "check" }); 096 } finally { 097 System.setOut(ps); 098 } 099 String sto = bs.toString(); 100 //System.out.println(sto); 101 assertTrue("sequential", sto.contains("sequential")); 102 assertTrue("sequential", sto.contains("seq+")); 103 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 104 assertTrue("check isGB = true", sto.contains("check isGB = true")); 105 } 106 107 108 /** 109 * Test parallel GB. 110 */ 111 public void testParallelGB() { 112 RunGB cli = new RunGB(); 113 PrintStream ps = System.out; 114 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 115 PrintStream ss = new PrintStream(bs); 116 try { 117 System.setOut(ss); 118 cli.main(new String[] { "par", "examples/trinks7.jas", "3", "check" }); 119 } finally { 120 System.setOut(ps); 121 } 122 String sto = bs.toString(); 123 //System.out.println(sto); 124 assertTrue("parallel", sto.contains("parallel")); 125 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 126 assertTrue("check isGB = true", sto.contains("check isGB = true")); 127 } 128 129 130 /** 131 * Test parallel GB plus. 132 */ 133 public void testParallelGBplus() { 134 RunGB cli = new RunGB(); 135 PrintStream ps = System.out; 136 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 137 PrintStream ss = new PrintStream(bs); 138 try { 139 System.setOut(ss); 140 cli.main(new String[] { "par+", "examples/trinks7.jas", "3", "check" }); 141 } finally { 142 System.setOut(ps); 143 } 144 String sto = bs.toString(); 145 //System.out.println(sto); 146 assertTrue("parallel", sto.contains("parallel")); 147 assertTrue("parallel", sto.contains("par+")); 148 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 149 assertTrue("check isGB = true", sto.contains("check isGB = true")); 150 } 151 152 153 /** 154 * Test with "build=" GB. 155 */ 156 public void testBuildGB() { 157 RunGB cli = new RunGB(); 158 PrintStream ps = System.out; 159 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 160 PrintStream ss = new PrintStream(bs); 161 try { 162 System.setOut(ss); 163 cli.main(new String[] { "build=syzygyPairlist.iterated.graded.parallel(3)", 164 "examples/trinks7.jas", "check" }); 165 } finally { 166 System.setOut(ps); 167 } 168 String sto = bs.toString(); 169 //System.out.println(sto); 170 assertTrue("iterated.graded.parallel", sto.contains("iterated.graded.parallel")); 171 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 172 assertTrue("check isGB = true", sto.contains("check isGB = true")); 173 } 174 175 176 /** 177 * Test distributed hybrid GB. 178 */ 179 public void testDisthybGB() { 180 RunGB cli = new RunGB(); 181 ExecutorService pool = ComputerThreads.getPool(); 182 RunGB node1 = new RunGB(); 183 RunGB node2 = new RunGB(); 184 PrintStream ps = System.out; 185 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 186 PrintStream ss = new PrintStream(bs); 187 try { 188 System.setOut(ss); 189 pool.execute( () -> node1.main(new String[] { "cli", "8114" }) ); 190 pool.execute( () -> node2.main(new String[] { "cli", "9114" }) ); 191 cli.main(new String[] { "disthyb", "examples/trinks7.jas", "3/2", "machines.localhost", "check" }); 192 } finally { 193 System.setOut(ps); 194 } 195 String sto = bs.toString(); 196 //System.out.println(sto); 197 assertTrue("disthyb", sto.contains("distributed hybrid")); 198 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 199 assertTrue("check isGB = true", sto.contains("check isGB = true")); 200 pool.shutdownNow(); 201 } 202 203 204 /** 205 * Test distributed hybrid GB plus. 206 */ 207 public void testDisthybGBplus() { 208 RunGB cli = new RunGB(); 209 ExecutorService pool = ComputerThreads.getPool(); 210 RunGB node1 = new RunGB(); 211 RunGB node2 = new RunGB(); 212 PrintStream ps = System.out; 213 ByteArrayOutputStream bs = new ByteArrayOutputStream(); 214 PrintStream ss = new PrintStream(bs); 215 try { 216 System.setOut(ss); 217 pool.execute( () -> node1.main(new String[] { "cli", "8114" }) ); 218 pool.execute( () -> node2.main(new String[] { "cli", "9114" }) ); 219 cli.main(new String[] { "disthyb+", "examples/trinks7.jas", "3/2", "machines.localhost", "check" }); 220 } finally { 221 System.setOut(ps); 222 } 223 String sto = bs.toString(); 224 //System.out.println(sto); 225 assertTrue("disthyb", sto.contains("distributed hybrid")); 226 assertTrue("disthyb", sto.contains("disthyb+")); 227 assertTrue("G.size() = 6", sto.contains("G.size() = 6")); 228 assertTrue("check isGB = true", sto.contains("check isGB = true")); 229 pool.shutdownNow(); 230 } 231 232}