PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/informatica-agent/src/test/java/org/bitbucket/bradleysmithllc/etlagent/informatica/provider/test/PmRepTest.java

https://bitbucket.org/bradleysmithllc/etl-agent
Java | 143 lines | 94 code | 29 blank | 20 comment | 2 complexity | f3cf5610d5c9eeb475f76bc1565eb140 MD5 | raw file
  1. package org.bitbucket.bradleysmithllc.etlagent.informatica.provider.test;
  2. /*
  3. * #%L
  4. * informatica-agent
  5. * %%
  6. * Copyright (C) 2012 - 2014 bradleysmithllc
  7. * %%
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. * #L%
  20. */
  21. import org.bitbucket.bradleysmithllc.etlagent.informatica.provider.PmRepProcess;
  22. import org.bitbucket.bradleysmithllc.etlagent.informatica.provider.PmRepProcessImpl;
  23. import org.bitbucket.bradleysmithllc.etlagent.informatica.provider.ProcessTimeoutException;
  24. import org.bitbucket.bradleysmithllc.etlunit.BasicRuntimeSupport;
  25. import org.bitbucket.bradleysmithllc.etlunit.PrintWriterLog;
  26. import org.bitbucket.bradleysmithllc.etlunit.ProcessFacade;
  27. import org.bitbucket.bradleysmithllc.etlunit.io.JavaForker;
  28. import org.junit.Assert;
  29. import org.junit.Test;
  30. import java.io.IOException;
  31. import java.util.Collections;
  32. import java.util.concurrent.CountDownLatch;
  33. public class PmRepTest {
  34. public static final int PERMITS = 1;
  35. @Test
  36. public void impost() throws Exception {
  37. BasicRuntimeSupport rs = new BasicRuntimeSupport();
  38. rs.setApplicationLogger(new PrintWriterLog());
  39. JavaForker forker = new JavaForker(rs);
  40. forker.setMainClass(PmRepImposter.class);
  41. forker.setOutput(rs.createAnonymousTempFile());
  42. ProcessFacade process = forker.startProcess();
  43. CountDownLatch cdl = new CountDownLatch(PERMITS);
  44. PmRepProcess pmRepProcess = new PmRepProcessImpl(process, rs, Collections.EMPTY_MAP, "id");
  45. for (int i = 0; i < PERMITS; i++)
  46. {
  47. new Thread(
  48. new PmRepper(pmRepProcess, cdl)//.run();
  49. ).start();
  50. }
  51. cdl.await();
  52. System.out.println("Disposing");
  53. pmRepProcess.dispose();
  54. }
  55. }
  56. class PmRepper implements Runnable {
  57. private final PmRepProcess pmRepProcess;
  58. private final CountDownLatch countDownLatch;
  59. PmRepper(PmRepProcess pmRepProcess, CountDownLatch cdl) {
  60. countDownLatch = cdl;
  61. this.pmRepProcess = pmRepProcess;
  62. }
  63. public void run() {
  64. try {
  65. Thread.currentThread().setName("repper-" + System.identityHashCode(this));
  66. run1();
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. throw new RuntimeException(e);
  70. } catch (ProcessTimeoutException e) {
  71. throw new RuntimeException(e);
  72. } finally
  73. {
  74. System.out.println(System.identityHashCode(this) + " countin' the latch down - " + countDownLatch.getCount());
  75. countDownLatch.countDown();
  76. System.out.println(System.identityHashCode(this) + " done - " + countDownLatch.getCount());
  77. }
  78. }
  79. public void run1() throws IOException, ProcessTimeoutException {
  80. // check for bogus command
  81. for (int i = 0; i < 2; i++) {
  82. System.out.println(System.identityHashCode(this) + "_" + i + "_1");
  83. String res = pmRepProcess.send("ping-" + i);
  84. Assert.assertEquals("ping-" + i + " is an unknown command. Type help to see a list of all available commands\r\n" +
  85. "pmrep>", res);
  86. System.out.println(System.identityHashCode(this) + "_" + i + "_2");
  87. res = pmRepProcess.send("connect -r REP_SVC_CI -n administrator -X INFAPASSWD -d DOM_CI");
  88. Assert.assertEquals("Connected to repository REP_SVC_CI in DOM_CI as user administrator\r\n" +
  89. "connect completed successfully.\r\n" +
  90. "pmrep>", res);
  91. System.out.println(System.identityHashCode(this) + "_" + i + "_3");
  92. pmRepProcess.send("ping-" + i);
  93. System.out.println(System.identityHashCode(this) + "_" + i + "_4");
  94. res = pmRepProcess.send("deletefolder -n __bsmith_f142aa7ae1ae71b191649b5bcef74816_SHARED_EDW");
  95. Assert.assertEquals("Deleting folder __bsmith_f142aa7ae1ae71b191649b5bcef74816_SHARED_EDW in repository REP_SVC_CI. All the data in the folder will be lost.\r\n" +
  96. "__bsmith_f142aa7ae1ae71b191649b5bcef74816_SHARED_EDW is a shared Folder. Deleting it will cause any shortcuts accessing it to become unusable.\r\n" +
  97. "deletefolder completed successfully.\r\n" +
  98. "pmrep>", res);
  99. System.out.println(System.identityHashCode(this) + "_" + i + "_5");
  100. pmRepProcess.send("ping-" + i);
  101. System.out.println(System.identityHashCode(this) + "_" + i + "_6");
  102. res = pmRepProcess.send("createfolder -n POS_NEW_TEST -s");
  103. Assert.assertEquals("Creating folder POS_NEW_TEST in repository REP_SVC_CI.\r\n" +
  104. "createfolder completed successfully.\r\n" +
  105. "pmrep>", res);
  106. System.out.println(System.identityHashCode(this) + "_" + i + "_7");
  107. pmRepProcess.send("ping-" + i);
  108. System.out.println(System.identityHashCode(this) + "_" + i + "_8");
  109. res = pmRepProcess.send("createconnection -s \"Microsoft SQL Server\" -n CONN_TEST -u jrottenseed -p clearTextPassword -v dbserver -b TEST_DB -e \"SET QUOTED_IDENTIFIER ON\" -l MS1252");
  110. Assert.assertEquals("createconnection completed successfully.\r\n" +
  111. "pmrep>", res);
  112. }
  113. }
  114. }