|
Added
Link Here
|
| 1 |
package org.eclipse.hyades.logging.adapter.tests.utils; |
| 2 |
/********************************************************************** |
| 3 |
* Copyright (c) 2006, 2007 IBM Corporation and others. |
| 4 |
* All rights reserved. This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* http://www.eclipse.org/legal/epl-v10.html |
| 8 |
* $Id: TestJUtils.java,v 1.6 2007/03/27 22:31:36 dnsmith Exp $ |
| 9 |
* |
| 10 |
* Contributors: |
| 11 |
* IBM - Initial API and implementation |
| 12 |
**********************************************************************/ |
| 13 |
|
| 14 |
import java.io.File; |
| 15 |
|
| 16 |
import org.eclipse.hyades.logging.adapter.Adapter; |
| 17 |
import org.eclipse.hyades.logging.adapter.AdapterException; |
| 18 |
import org.eclipse.hyades.logging.adapter.IComponent; |
| 19 |
import org.eclipse.hyades.logging.adapter.IContext; |
| 20 |
import org.eclipse.hyades.logging.adapter.IStatus; |
| 21 |
import org.eclipse.hyades.logging.adapter.outputters.CBEFileOutputter; |
| 22 |
import org.eclipse.hyades.logging.adapter.sensors.SingleOSFileSensor; |
| 23 |
|
| 24 |
import org.eclipse.hyades.test.common.junit.HyadesTestCase; |
| 25 |
import org.eclipse.tptp.monitoring.auto.tests.utils.PropertiesWrapper; |
| 26 |
|
| 27 |
/** |
| 28 |
* This is the main class to run GLA API tests and check the results |
| 29 |
* |
| 30 |
*/ |
| 31 |
|
| 32 |
public class APITestJUtils extends HyadesTestCase |
| 33 |
{ |
| 34 |
public APITestJUtils(String arg0) |
| 35 |
{ |
| 36 |
super(arg0); |
| 37 |
} |
| 38 |
|
| 39 |
private static String getActualFile(String relativeFile) |
| 40 |
{ |
| 41 |
return PropertiesWrapper.DEPLOYMENT_HOME + "/" + relativeFile; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static void testInvalidSetContextConfigPathAPI(String adapterConfigFile) |
| 47 |
{ |
| 48 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 49 |
Adapter adapter = new Adapter(); |
| 50 |
adapter.setContextConfigPath("c:\\dummy.adapter"); //does not exist |
| 51 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 52 |
/* Get the adapter configuration */ |
| 53 |
|
| 54 |
try { |
| 55 |
adapter.getConfiguration(); |
| 56 |
} |
| 57 |
catch (AdapterException e) { |
| 58 |
return; |
| 59 |
} |
| 60 |
catch(Throwable e) |
| 61 |
{ |
| 62 |
// Fail since we are supposed to get an AdapterException |
| 63 |
fail("Expected AdapterException - Error: " + e); |
| 64 |
} |
| 65 |
fail("AdapterException was not thrown due to invalid path"); |
| 66 |
} |
| 67 |
|
| 68 |
public static void testInvalidAdapterSetContextConfigPathAPI(String invalidAdapterFile,String adapterConfigFile) |
| 69 |
{ |
| 70 |
invalidAdapterFile = getActualFile(invalidAdapterFile); |
| 71 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 72 |
Adapter adapter = new Adapter(); |
| 73 |
adapter.setContextConfigPath(invalidAdapterFile); //invalid content |
| 74 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 75 |
/* Get the adapter configuration */ |
| 76 |
|
| 77 |
try { |
| 78 |
adapter.getConfiguration(); |
| 79 |
} |
| 80 |
catch (AdapterException e) { |
| 81 |
return; |
| 82 |
} |
| 83 |
catch(Throwable e) |
| 84 |
{ |
| 85 |
// Fail since we are supposed to get an AdapterException |
| 86 |
fail("Expected AdapterException - Error: " + e); |
| 87 |
} |
| 88 |
|
| 89 |
fail("AdapterException was not thrown due to invalid adapter content"); |
| 90 |
} |
| 91 |
|
| 92 |
public static void testInvalidSetComponentConfigPathAPI(String adapterConfigFile) |
| 93 |
{ |
| 94 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 95 |
Adapter adapter = new Adapter(); |
| 96 |
adapter.setContextConfigPath(adapterConfigFile); //does not exist |
| 97 |
adapter.setComponentConfigPath("c:\\dummy.adapter"); |
| 98 |
/* Get the adapter configuration */ |
| 99 |
|
| 100 |
try { |
| 101 |
adapter.getConfiguration(); |
| 102 |
} |
| 103 |
catch (AdapterException e) { |
| 104 |
return; |
| 105 |
} |
| 106 |
catch(Throwable e) |
| 107 |
{ |
| 108 |
// Fail since we are supposed to get an AdapterException |
| 109 |
fail("Expected AdapterException - Error: " + e); |
| 110 |
} |
| 111 |
|
| 112 |
fail("AdapterException was not thrown due to invalid path"); |
| 113 |
} |
| 114 |
|
| 115 |
public static void testInvalidAdapterSetComponentConfigPathAPI(String invalidAdapterFile,String adapterConfigFile) |
| 116 |
{ |
| 117 |
invalidAdapterFile = getActualFile(invalidAdapterFile); |
| 118 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 119 |
Adapter adapter = new Adapter(); |
| 120 |
adapter.setContextConfigPath(adapterConfigFile); //does not exist |
| 121 |
adapter.setComponentConfigPath(invalidAdapterFile); |
| 122 |
/* Get the adapter configuration */ |
| 123 |
|
| 124 |
try { |
| 125 |
adapter.getConfiguration(); |
| 126 |
} |
| 127 |
catch (AdapterException e) { |
| 128 |
return; |
| 129 |
} |
| 130 |
catch(Throwable e) |
| 131 |
{ |
| 132 |
// Fail since we are supposed to get an AdapterException |
| 133 |
fail("Expected AdapterException - Error: " + e); |
| 134 |
} |
| 135 |
|
| 136 |
fail("AdapterException was not thrown due to invalid adapter content"); |
| 137 |
} |
| 138 |
|
| 139 |
public static void testValidDiffFileSetContextComponentConfigPathAPI(String contextConfigFile,String componentConfigFile) |
| 140 |
{ |
| 141 |
contextConfigFile = getActualFile(contextConfigFile); |
| 142 |
componentConfigFile = getActualFile(componentConfigFile); |
| 143 |
Adapter adapter = new Adapter(); |
| 144 |
adapter.setContextConfigPath(contextConfigFile); |
| 145 |
adapter.setComponentConfigPath(componentConfigFile); |
| 146 |
/* Get the adapter configuration */ |
| 147 |
IContext [] contexts = null; |
| 148 |
|
| 149 |
try { |
| 150 |
contexts = adapter.getConfiguration(); |
| 151 |
assertNotNull(contexts); |
| 152 |
} |
| 153 |
catch (AdapterException e) { |
| 154 |
fail(e.getMessage()); |
| 155 |
} |
| 156 |
catch(Throwable e) |
| 157 |
{ |
| 158 |
// Fail since we are supposed to get an AdapterException |
| 159 |
fail("Expected AdapterException - Error: " + e); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
public static void testSetLoggingLevelAPI(String adapterConfigFile) |
| 164 |
{ |
| 165 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 166 |
Adapter adapter = new Adapter(); |
| 167 |
adapter.setContextConfigPath(adapterConfigFile); |
| 168 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 169 |
|
| 170 |
adapter.setLoggingLevel((short)0); |
| 171 |
/* Get the adapter configuration */ |
| 172 |
IContext [] contexts = null; |
| 173 |
|
| 174 |
try |
| 175 |
{ |
| 176 |
contexts = adapter.getConfiguration(); |
| 177 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 178 |
SingleOSFileSensor sensor = (SingleOSFileSensor)contexts[0].getComponents()[0]; |
| 179 |
|
| 180 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 181 |
sensor.setFileName("example.log"); |
| 182 |
assertNotSame(adapter.getLoggingLevel(), contexts[0].getLoggingLevel()); |
| 183 |
adapter.start(true, true); |
| 184 |
assertNotNull(contexts); |
| 185 |
} |
| 186 |
catch (AdapterException e) { |
| 187 |
adapter.stop(); |
| 188 |
fail(e.getMessage()); |
| 189 |
} |
| 190 |
catch(Throwable e) |
| 191 |
{ |
| 192 |
adapter.stop(); |
| 193 |
// Fail since we are supposed to get an AdapterException |
| 194 |
fail("Expected AdapterException - Error: " + e); |
| 195 |
} |
| 196 |
|
| 197 |
try { |
| 198 |
Thread.sleep(3000); |
| 199 |
} |
| 200 |
catch (InterruptedException e) {} |
| 201 |
adapter.stop(); |
| 202 |
assertEquals(adapter.getLoggingLevel(), contexts[0].getLoggingLevel()); |
| 203 |
} |
| 204 |
|
| 205 |
public static void testGetLoggingLevelAPI(String adapterConfigFile) |
| 206 |
{ |
| 207 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 208 |
Adapter adapter = new Adapter(); |
| 209 |
adapter.setContextConfigPath(adapterConfigFile); |
| 210 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 211 |
|
| 212 |
adapter.setLoggingLevel((short)10); |
| 213 |
assertEquals(adapter.getLoggingLevel(), 10); |
| 214 |
} |
| 215 |
|
| 216 |
public static void testGetLoggingLevelAPIDefaultValue(String adapterConfigFile) |
| 217 |
{ |
| 218 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 219 |
Adapter adapter = new Adapter(); |
| 220 |
adapter.setContextConfigPath(adapterConfigFile); |
| 221 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 222 |
|
| 223 |
assertEquals(adapter.getLoggingLevel(), -1); |
| 224 |
} |
| 225 |
|
| 226 |
public static void testValidGetConfigurationAPI(String adapterConfigFile) |
| 227 |
{ |
| 228 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 229 |
Adapter adapter = new Adapter(); |
| 230 |
adapter.setContextConfigPath(adapterConfigFile); //does not exist |
| 231 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 232 |
|
| 233 |
try |
| 234 |
{ |
| 235 |
IContext [] contexts = adapter.getConfiguration(); |
| 236 |
assertNotNull(contexts); |
| 237 |
} |
| 238 |
catch (AdapterException e) { |
| 239 |
fail(e.getMessage()); |
| 240 |
} |
| 241 |
catch(Throwable e) |
| 242 |
{ |
| 243 |
// Fail since we are supposed to get an AdapterException |
| 244 |
fail("Expected AdapterException - Error: " + e); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
public static void testInvalidGetConfigurationAPI(String adapterConfigFile) |
| 249 |
{ |
| 250 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 251 |
Adapter adapter = new Adapter(); |
| 252 |
adapter.setContextConfigPath(adapterConfigFile); |
| 253 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 254 |
|
| 255 |
try |
| 256 |
{ |
| 257 |
adapter.getConfiguration(); |
| 258 |
} |
| 259 |
catch (AdapterException e) { |
| 260 |
return; |
| 261 |
} |
| 262 |
catch(Throwable e) |
| 263 |
{ |
| 264 |
// Fail since we are supposed to get an AdapterException |
| 265 |
fail("Expected AdapterException - Error: " + e); |
| 266 |
} |
| 267 |
fail("Invalid configuration did not throw any errors"); |
| 268 |
} |
| 269 |
|
| 270 |
public static void testInvalidNoPathGetConfigurationAPI() |
| 271 |
{ |
| 272 |
Adapter adapter = new Adapter(); |
| 273 |
try |
| 274 |
{ |
| 275 |
adapter.getConfiguration(); |
| 276 |
} |
| 277 |
catch (AdapterException e) { |
| 278 |
return; |
| 279 |
} |
| 280 |
catch(Throwable e) |
| 281 |
{ |
| 282 |
// Fail since we are supposed to get an AdapterException |
| 283 |
fail("Expected AdapterException - Error: " + e); |
| 284 |
} |
| 285 |
fail("Invalid configuration did not throw any errors"); |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public static void testSuccessValidateAPI(String adapterConfigFile) |
| 291 |
{ |
| 292 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 293 |
Adapter adapter = new Adapter(); |
| 294 |
adapter.setContextConfigPath(adapterConfigFile); |
| 295 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 296 |
|
| 297 |
adapter.setLoggingLevel((short)0); |
| 298 |
/* Get the adapter configuration */ |
| 299 |
IContext [] contexts = null; |
| 300 |
|
| 301 |
try |
| 302 |
{ |
| 303 |
contexts = adapter.getConfiguration(); |
| 304 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 305 |
SingleOSFileSensor sensor = (SingleOSFileSensor)contexts[0].getComponents()[0]; |
| 306 |
|
| 307 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 308 |
sensor.setFileName("example.log"); |
| 309 |
adapter.validate(); |
| 310 |
} |
| 311 |
catch (AdapterException e) { |
| 312 |
fail(e.getMessage()); |
| 313 |
} |
| 314 |
catch(Throwable e) |
| 315 |
{ |
| 316 |
// Fail since we are supposed to get an AdapterException |
| 317 |
fail("Expected AdapterException - Error: " + e); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
public static void testFailedNoPathValidateAPI() |
| 323 |
{ |
| 324 |
Adapter adapter = new Adapter(); |
| 325 |
try |
| 326 |
{ |
| 327 |
adapter.validate(); |
| 328 |
} |
| 329 |
catch (AdapterException e) { |
| 330 |
return; |
| 331 |
} |
| 332 |
catch(Throwable e) |
| 333 |
{ |
| 334 |
// Fail since we are supposed to get an AdapterException |
| 335 |
fail(e.getMessage()); |
| 336 |
} |
| 337 |
fail("Invalid configuration in the adapter did not throw any exception during validate()"); |
| 338 |
} |
| 339 |
|
| 340 |
public static void testFailedValidateAPI(String adapterConfigFile) |
| 341 |
{ |
| 342 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 343 |
Adapter adapter = new Adapter(); |
| 344 |
adapter.setContextConfigPath(adapterConfigFile); |
| 345 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 346 |
|
| 347 |
/* Get the adapter configuration */ |
| 348 |
try |
| 349 |
{ |
| 350 |
adapter.validate(); |
| 351 |
} |
| 352 |
catch (AdapterException e) { |
| 353 |
return; |
| 354 |
} |
| 355 |
catch(Throwable e) |
| 356 |
{ |
| 357 |
// Fail since we are supposed to get an AdapterException |
| 358 |
fail("Expected AdapterException - Error: " + e); |
| 359 |
} |
| 360 |
fail("Invalid configuration in the adapter did not throw any exception during validate()"); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
public static void testStartThreadDeamonModeAPI(String adapterConfigFile) |
| 365 |
{ |
| 366 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 367 |
Adapter adapter = new Adapter(); |
| 368 |
adapter.setContextConfigPath(adapterConfigFile); |
| 369 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 370 |
|
| 371 |
try |
| 372 |
{ |
| 373 |
IContext [] contexts = adapter.getConfiguration(); |
| 374 |
IComponent[] components = contexts[0].getComponents(); |
| 375 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 376 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 377 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 378 |
sensor.setFileName("example.log"); |
| 379 |
|
| 380 |
/* Get the outputter and update the directory and file name of the output file */ |
| 381 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 382 |
outputter.setFileName("startTest1.out"); |
| 383 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 384 |
|
| 385 |
adapter.start(true, true); |
| 386 |
} |
| 387 |
catch (AdapterException e) { |
| 388 |
adapter.stop(); |
| 389 |
fail(e.getMessage()); |
| 390 |
} |
| 391 |
catch(Throwable e) |
| 392 |
{ |
| 393 |
adapter.stop(); |
| 394 |
// Fail since we are supposed to get an AdapterException |
| 395 |
fail("Expected AdapterException - Error: " + e); |
| 396 |
} |
| 397 |
|
| 398 |
try { |
| 399 |
Thread.sleep(3000); |
| 400 |
} |
| 401 |
catch (InterruptedException e) {} |
| 402 |
adapter.stop(); |
| 403 |
assertTrue("Out file was not generated", (new File(new File(adapterConfigFile).getParent() + "/startTest1.out")).exists()); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
public static void testStartNonThreadModeAPI(String adapterConfigFile) |
| 409 |
{ |
| 410 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 411 |
Adapter adapter = new Adapter(); |
| 412 |
adapter.setContextConfigPath(adapterConfigFile); |
| 413 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 414 |
|
| 415 |
adapter.setLoggingLevel((short)0); |
| 416 |
|
| 417 |
try |
| 418 |
{ |
| 419 |
IContext [] contexts = adapter.getConfiguration(); |
| 420 |
IComponent[] components = contexts[0].getComponents(); |
| 421 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 422 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 423 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 424 |
sensor.setFileName("example.log"); |
| 425 |
|
| 426 |
/* Get the outputter and update the directory and file name of the output file */ |
| 427 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 428 |
outputter.setFileName("startTest2.out"); |
| 429 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 430 |
|
| 431 |
adapter.start(false, false); |
| 432 |
} |
| 433 |
catch (AdapterException e) { |
| 434 |
adapter.stop(); |
| 435 |
fail(e.getMessage()); |
| 436 |
} |
| 437 |
catch(Throwable e) |
| 438 |
{ |
| 439 |
adapter.stop(); |
| 440 |
// Fail since we are supposed to get an AdapterException |
| 441 |
fail("Expected AdapterException - Error: " + e); |
| 442 |
} |
| 443 |
|
| 444 |
try { |
| 445 |
Thread.sleep(3000); |
| 446 |
} |
| 447 |
catch (InterruptedException e) {} |
| 448 |
adapter.stop(); |
| 449 |
assertTrue("Out file was not generated", (new File(new File(adapterConfigFile).getParent() + "/startTest2.out")).exists()); |
| 450 |
} |
| 451 |
|
| 452 |
public static void testStartInvalidAdapterModeAPI() |
| 453 |
{ |
| 454 |
Adapter adapter = new Adapter(); |
| 455 |
try |
| 456 |
{ |
| 457 |
adapter.start(true, true); |
| 458 |
} |
| 459 |
catch (AdapterException e) { |
| 460 |
adapter.stop(); |
| 461 |
return; |
| 462 |
} |
| 463 |
catch(Throwable e) |
| 464 |
{ |
| 465 |
adapter.stop(); |
| 466 |
// Fail since we are supposed to get an AdapterException |
| 467 |
fail("Expected AdapterException - Error: " + e); |
| 468 |
} |
| 469 |
adapter.stop(); |
| 470 |
fail("Exception not thrown for invalid adapter"); |
| 471 |
} |
| 472 |
|
| 473 |
public static void testSetLogOutputterAPI(String adapterConfigFile) |
| 474 |
{ |
| 475 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 476 |
Adapter adapter = new Adapter(); |
| 477 |
adapter.setContextConfigPath(adapterConfigFile); |
| 478 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 479 |
|
| 480 |
adapter.setLoggingLevel((short)0); |
| 481 |
|
| 482 |
try |
| 483 |
{ |
| 484 |
/* Create a file outputter to capture GLA |
| 485 |
* log messages. |
| 486 |
*/ |
| 487 |
CBEFileOutputter fo = new CBEFileOutputter(); |
| 488 |
fo.setDirectory(new File(adapterConfigFile).getParent()); |
| 489 |
fo.setFileName("testgla1.log"); |
| 490 |
|
| 491 |
/* Set the outputter to capture the GLA log messages */ |
| 492 |
adapter.setLogOutputter(fo); |
| 493 |
|
| 494 |
IContext [] contexts = adapter.getConfiguration(); |
| 495 |
IComponent[] components = contexts[0].getComponents(); |
| 496 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 497 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 498 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 499 |
sensor.setFileName("example.log"); |
| 500 |
|
| 501 |
/* Get the outputter and update the directory and file name of the output file */ |
| 502 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 503 |
outputter.setFileName("sample.out"); |
| 504 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 505 |
|
| 506 |
adapter.start(false, false); |
| 507 |
} |
| 508 |
catch (AdapterException e) { |
| 509 |
adapter.stop(); |
| 510 |
fail(e.getMessage()); |
| 511 |
} |
| 512 |
catch(Throwable e) |
| 513 |
{ |
| 514 |
adapter.stop(); |
| 515 |
// Fail since we are supposed to get an AdapterException |
| 516 |
fail("Expected AdapterException - Error: " + e); |
| 517 |
} |
| 518 |
|
| 519 |
try { |
| 520 |
Thread.sleep(3000); |
| 521 |
} |
| 522 |
catch (InterruptedException e) {} |
| 523 |
adapter.stop(); |
| 524 |
File result = (new File(new File(adapterConfigFile).getParent() + "/testgla1.log")); |
| 525 |
assertTrue("Out file " + result.getAbsolutePath()+ "was not generated", (result.exists() && result.length() > 0)); |
| 526 |
} |
| 527 |
|
| 528 |
public static void testStopAPI(String adapterConfigFile) |
| 529 |
{ |
| 530 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 531 |
Adapter adapter = new Adapter(); |
| 532 |
adapter.setContextConfigPath(adapterConfigFile); |
| 533 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 534 |
|
| 535 |
try |
| 536 |
{ |
| 537 |
IContext [] contexts = adapter.getConfiguration(); |
| 538 |
IComponent[] components = contexts[0].getComponents(); |
| 539 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 540 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 541 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 542 |
sensor.setFileName("example.log"); |
| 543 |
|
| 544 |
/* Get the outputter and update the directory and file name of the output file */ |
| 545 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 546 |
outputter.setFileName("apacheaccess.out"); |
| 547 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 548 |
|
| 549 |
adapter.start(true, true); |
| 550 |
} |
| 551 |
catch (AdapterException e) { |
| 552 |
adapter.stop(); |
| 553 |
fail(e.getMessage()); |
| 554 |
} |
| 555 |
catch(Throwable e) |
| 556 |
{ |
| 557 |
adapter.stop(); |
| 558 |
// Fail since we are supposed to get an AdapterException |
| 559 |
fail("Expected AdapterException - Error: " + e); |
| 560 |
} |
| 561 |
|
| 562 |
try { |
| 563 |
Thread.sleep(3000); |
| 564 |
} |
| 565 |
catch (InterruptedException e) {} |
| 566 |
adapter.stop(); |
| 567 |
|
| 568 |
/* Get the adapter status */ |
| 569 |
IStatus status = adapter.getStatus(); |
| 570 |
|
| 571 |
if (status != null) { |
| 572 |
assertFalse("Adapter has not stopped",status.isActive()); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
public static void testHardStopAPI(String adapterConfigFile) |
| 578 |
{ |
| 579 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 580 |
Adapter adapter = new Adapter(); |
| 581 |
adapter.setContextConfigPath(adapterConfigFile); |
| 582 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 583 |
|
| 584 |
try |
| 585 |
{ |
| 586 |
IContext [] contexts = adapter.getConfiguration(); |
| 587 |
IComponent[] components = contexts[0].getComponents(); |
| 588 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 589 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 590 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 591 |
sensor.setFileName("example.log"); |
| 592 |
|
| 593 |
/* Get the outputter and update the directory and file name of the output file */ |
| 594 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 595 |
outputter.setFileName("apacheaccess.out"); |
| 596 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 597 |
|
| 598 |
adapter.start(true, true); |
| 599 |
} |
| 600 |
catch (AdapterException e) { |
| 601 |
adapter.stop(); |
| 602 |
fail(e.getMessage()); |
| 603 |
} |
| 604 |
catch(Throwable e) |
| 605 |
{ |
| 606 |
adapter.stop(); |
| 607 |
// Fail since we are supposed to get an AdapterException |
| 608 |
fail("Expected AdapterException - Error: " + e); |
| 609 |
} |
| 610 |
|
| 611 |
try { |
| 612 |
Thread.sleep(3000); |
| 613 |
} |
| 614 |
catch (InterruptedException e) {} |
| 615 |
adapter.hardStop(); |
| 616 |
try { |
| 617 |
Thread.sleep(3000); |
| 618 |
} |
| 619 |
catch (InterruptedException e) {} |
| 620 |
/* Get the adapter status */ |
| 621 |
IStatus status = adapter.getStatus(); |
| 622 |
|
| 623 |
if (status != null) { |
| 624 |
assertFalse("Adapter has not stopped",status.isActive()); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
public static void testGetStatusAPI(String adapterConfigFile) |
| 630 |
{ |
| 631 |
adapterConfigFile = getActualFile(adapterConfigFile); |
| 632 |
Adapter adapter = new Adapter(); |
| 633 |
adapter.setContextConfigPath(adapterConfigFile); |
| 634 |
adapter.setComponentConfigPath(adapterConfigFile); |
| 635 |
|
| 636 |
try |
| 637 |
{ |
| 638 |
IContext [] contexts = adapter.getConfiguration(); |
| 639 |
IComponent[] components = contexts[0].getComponents(); |
| 640 |
/* Get the sensor and update the directory and file name of the log to parse */ |
| 641 |
SingleOSFileSensor sensor = (SingleOSFileSensor)components[0]; |
| 642 |
sensor.setDirectory(new File(adapterConfigFile).getParent()); |
| 643 |
sensor.setFileName("example.log"); |
| 644 |
|
| 645 |
/* Get the outputter and update the directory and file name of the output file */ |
| 646 |
CBEFileOutputter outputter = (CBEFileOutputter)components[components.length-1]; |
| 647 |
outputter.setFileName("apacheaccess.out"); |
| 648 |
outputter.setDirectory(new File(adapterConfigFile).getParent()); |
| 649 |
|
| 650 |
adapter.start(true, true); |
| 651 |
} |
| 652 |
catch (AdapterException e) { |
| 653 |
adapter.stop(); |
| 654 |
fail(e.getMessage()); |
| 655 |
} |
| 656 |
catch(Throwable e) |
| 657 |
{ |
| 658 |
adapter.stop(); |
| 659 |
// Fail since we are supposed to get an AdapterException |
| 660 |
fail("Expected AdapterException - Error: " + e); |
| 661 |
} |
| 662 |
|
| 663 |
try { |
| 664 |
Thread.sleep(3000); |
| 665 |
} |
| 666 |
catch (InterruptedException e) {} |
| 667 |
|
| 668 |
|
| 669 |
/* Get the adapter status */ |
| 670 |
IStatus status = adapter.getStatus(); |
| 671 |
if (status != null) { |
| 672 |
long time = status.getElapsedTimeInMilliseconds(); |
| 673 |
int processed = status.getItemsProcessedCount(); |
| 674 |
adapter.stop(); |
| 675 |
assertTrue("Adapter has invalid status",(time > 0 && processed > 0)); |
| 676 |
} |
| 677 |
else |
| 678 |
{ |
| 679 |
adapter.stop(); |
| 680 |
fail("Status object is null"); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
public static void main(String[] arg) |
| 685 |
{ |
| 686 |
testStopAPI("D:\\TPTP_4_4\\build_tptp\\GenericLogAdapter\\config\\Apache\\access\\v1.3.26\\regex_example.adapter"); |
| 687 |
} |
| 688 |
|
| 689 |
} |