<commit_before>package alma.acs.lasercore.test.reductions;

import java.sql.Timestamp;

import cern.laser.source.alarmsysteminterface.FaultState;
import alma.acs.component.client.ComponentClientTestCase;
import alma.acs.lasercore.test.stress.CategoryClient;
import alma.acs.lasercore.test.stress.category.AlarmView;
import alma.acs.lasercore.test.stress.category.CategoryListener;
import alma.alarmsystem.source.ACSAlarmSystemInterface;
import alma.alarmsystem.source.ACSAlarmSystemInterfaceFactory;
import alma.alarmsystem.source.ACSFaultState;

/**
 * Check the functioning of RR with regular expressions / wildcards
 * 
 * @author acaproni
 *
 */
public class RRWithRegExp extends ComponentClientTestCase implements CategoryListener{
	
	/**
	 * The category client to listen to alarms
	 */
	private CategoryClient categoryClient;
	
	/**
	 * The alarm source
	 */
	private ACSAlarmSystemInterface alarmSource;
	
	/**
	 * Constructor 
	 * 
	 * @param name The name of the test
	 * @throws Exception
	 */
	public RRWithRegExp() throws Exception {
		super(RRWithRegExp.class.getName());
		System.out.println("Test built");
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		categoryClient = new CategoryClient(this.getContainerServices());
		assertNotNull(categoryClient);
		categoryClient.connect();
		categoryClient.addAlarmListener(this);
		alarmSource = ACSAlarmSystemInterfaceFactory.createSource();
		assertNotNull(alarmSource);
		System.out.println("setUp done");
	}

	@Override
	protected void tearDown() throws Exception {
		ACSAlarmSystemInterfaceFactory.done();
		categoryClient.close();
		super.tearDown();
		System.out.println("tearDown done");
	}

	/**
	 * @param alarm
	 * @see {@link AlarmSelectionListener}
	 */
	@Override
	public void alarmReceived(AlarmView alarm) {
		System.out.print("Alarm received: "+alarm.alarmID+" active="+alarm.active);
		System.out.print(", nodeC="+alarm.nodeChild);
		System.out.print(", nodeP="+alarm.nodeParent);
		System.out.print(", multiC="+alarm.multiplicityChild);
		System.out.print(", multiP="+alarm.multiplicityParent);
		System.out.print(", reduced="+alarm.reduced);
		System.out.println(", masked="+alarm.masked);
	}

	/**
	 * Test the MULTIPLICITY and NODE reduction 
	 * 
	 * <B>Note</B>: initially I wrote 2 test for distinguishing between
	 * 				NODe and MULTILPICITY but there is something going wrong 
	 * 				when the alarms for the second tests are published: SimpleSupplier.publishEvent 
	 * 				hangs probably due to some misuse of static variables.
	 * 				I have decided to condesate the 2 tests in only one.
	 * 
	 * @TODO Split this test in two test when the problem described upon has been fixed.
	 * 
	 * @throws Exception
	 */
	public void testReductions() throws Exception {
		System.out.println("testMultiplicity");
		// Send the alarms to trigger the reduction
		sendAlarm("MF_REGEXP", "REGEXP1", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP2", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP3", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP4", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP5", 0, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("MF_REGEXP", "REGEXP1", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP2", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP3", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP4", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP5", 0, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		////////////////////////////////////////////////////////////////////
		System.out.println("testNode");
		sendAlarm("NODE_REGEXP", "REGEXP_NODE1", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_2", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_3", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_4", 1, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("NODE_REGEXP", "REGEXP_NODE1",  1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_2", 1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_3", 1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_4", 1, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		System.out.println("testMultiplicity with regexp and default FM");
		// Send the alarms to trigger the reduction
		sendAlarm("NODE_DEFAULT", "DA41", 1, true);
		sendAlarm("NODE_DEFAULT", "DA42", 1, true);
		sendAlarm("NODE_DEFAULT", "DA43", 1, true);
		sendAlarm("NODE_DEFAULT", "DA44", 1, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("NODE_DEFAULT", "DA41",  1, false);
		sendAlarm("NODE_DEFAULT", "DA42", 1, false);
		sendAlarm("NODE_DEFAULT", "DA43", 1, false);
		sendAlarm("NODE_DEFAULT", "DA44", 1, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		System.out.println("testMultiplicity with hierarchical FM, regexp and default FM");
		// Send the alarms to trigger the reduction
		sendAlarm("HIERARCHICAL", "CONTROL/DA41/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA42/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA43/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA44/HIER", 1, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("HIERARCHICAL", "CONTROL/DA41/HIER",  1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA42/HIER", 1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA43/HIER", 1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA44/HIER", 1, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
	}

	/**
	 * Send an alarm
	 * 
	 * @param FF The fault family<commit_msg>Set NODE_DEFAULT alarms with a different FC to avoid clashes<commit_after>package alma.acs.lasercore.test.reductions;

import java.sql.Timestamp;

import cern.laser.source.alarmsysteminterface.FaultState;
import alma.acs.component.client.ComponentClientTestCase;
import alma.acs.lasercore.test.stress.CategoryClient;
import alma.acs.lasercore.test.stress.category.AlarmView;
import alma.acs.lasercore.test.stress.category.CategoryListener;
import alma.alarmsystem.source.ACSAlarmSystemInterface;
import alma.alarmsystem.source.ACSAlarmSystemInterfaceFactory;
import alma.alarmsystem.source.ACSFaultState;

/**
 * Check the functioning of RR with regular expressions / wildcards
 * 
 * @author acaproni
 *
 */
public class RRWithRegExp extends ComponentClientTestCase implements CategoryListener{
	
	/**
	 * The category client to listen to alarms
	 */
	private CategoryClient categoryClient;
	
	/**
	 * The alarm source
	 */
	private ACSAlarmSystemInterface alarmSource;
	
	/**
	 * Constructor 
	 * 
	 * @param name The name of the test
	 * @throws Exception
	 */
	public RRWithRegExp() throws Exception {
		super(RRWithRegExp.class.getName());
		System.out.println("Test built");
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		categoryClient = new CategoryClient(this.getContainerServices());
		assertNotNull(categoryClient);
		categoryClient.connect();
		categoryClient.addAlarmListener(this);
		alarmSource = ACSAlarmSystemInterfaceFactory.createSource();
		assertNotNull(alarmSource);
		System.out.println("setUp done");
	}

	@Override
	protected void tearDown() throws Exception {
		ACSAlarmSystemInterfaceFactory.done();
		categoryClient.close();
		super.tearDown();
		System.out.println("tearDown done");
	}

	/**
	 * @param alarm
	 * @see {@link AlarmSelectionListener}
	 */
	@Override
	public void alarmReceived(AlarmView alarm) {
		System.out.print("Alarm received: "+alarm.alarmID+" active="+alarm.active);
		System.out.print(", nodeC="+alarm.nodeChild);
		System.out.print(", nodeP="+alarm.nodeParent);
		System.out.print(", multiC="+alarm.multiplicityChild);
		System.out.print(", multiP="+alarm.multiplicityParent);
		System.out.print(", reduced="+alarm.reduced);
		System.out.println(", masked="+alarm.masked);
	}

	/**
	 * Test the MULTIPLICITY and NODE reduction 
	 * 
	 * <B>Note</B>: initially I wrote 2 test for distinguishing between
	 * 				NODe and MULTILPICITY but there is something going wrong 
	 * 				when the alarms for the second tests are published: SimpleSupplier.publishEvent 
	 * 				hangs probably due to some misuse of static variables.
	 * 				I have decided to condesate the 2 tests in only one.
	 * 
	 * @TODO Split this test in two test when the problem described upon has been fixed.
	 * 
	 * @throws Exception
	 */
	public void testReductions() throws Exception {
		System.out.println("testMultiplicity");
		// Send the alarms to trigger the reduction
		sendAlarm("MF_REGEXP", "REGEXP1", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP2", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP3", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP4", 0, true);
		sendAlarm("MF_REGEXP", "REGEXP5", 0, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("MF_REGEXP", "REGEXP1", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP2", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP3", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP4", 0, false);
		sendAlarm("MF_REGEXP", "REGEXP5", 0, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		////////////////////////////////////////////////////////////////////
		System.out.println("testNode");
		sendAlarm("NODE_REGEXP", "REGEXP_NODE1", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_2", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_3", 1, true);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_4", 1, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("NODE_REGEXP", "REGEXP_NODE1",  1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_2", 1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_3", 1, false);
		sendAlarm("NODE_REGEXP", "REGEXP_NODE_4", 1, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		System.out.println("testMultiplicity with regexp and default FM");
		// Send the alarms to trigger the reduction
		sendAlarm("NODE_DEFAULT", "DA41", 3, true);
		sendAlarm("NODE_DEFAULT", "DA42", 3, true);
		sendAlarm("NODE_DEFAULT", "DA43", 3, true);
		sendAlarm("NODE_DEFAULT", "DA44", 3, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("NODE_DEFAULT", "DA41",  3, false);
		sendAlarm("NODE_DEFAULT", "DA42", 3, false);
		sendAlarm("NODE_DEFAULT", "DA43", 3, false);
		sendAlarm("NODE_DEFAULT", "DA44", 3, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		
		System.out.println("testMultiplicity with hierarchical FM, regexp and default FM");
		// Send the alarms to trigger the reduction
		sendAlarm("HIERARCHICAL", "CONTROL/DA41/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA42/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA43/HIER", 1, true);
		sendAlarm("HIERARCHICAL", "CONTROL/DA44/HIER", 1, true);
		// Give time for the reduced alarm to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
		// Clear the alarms
		sendAlarm("HIERARCHICAL", "CONTROL/DA41/HIER",  1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA42/HIER", 1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA43/HIER", 1, false);
		sendAlarm("HIERARCHICAL", "CONTROL/DA44/HIER", 1, false);
		// Give time for the alarms to arrive
		try {
			Thread.sleep(10000);
		} catch (InterruptedException i) {}
	}

	/**
	 * Send an alarm
	 * 
	 * @param FF The fault family
{'fraction_non_alphanumeric': 0.14432819836889366, 'fraction_numerical': 0.02075953538182717, 'mean_word_length': 4.250865051903114, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5836800', 'n_tokens_mistral': 4467, 'n_tokens_neox': 3940, 'n_words': 998}