Decided to wire up a simple speech writing application as a test bed for learning Speech Recognition + F#. To allow the speech recognition to be started or stopped I wired up the following methods:
let Activate () =
sp.RecognizeAsync(RecognizeMode.Multiple)
let Deactivate () =
sp.RecognizeAsyncCancel()
sp.RecognizeAsyncStop()
I can start the engine fine with the default grammar dictionary. The problem comes whens I call the deactivate method. I often get the following exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
Additional information: Cannot perform this operation while the recognizer is doing recognition.
See here.
There appear to be two issues with your code:
You should either call RecognizeAsyncCancel or RecognizeAsyncStop, but not both. They do the same thing except that RecognizeAysncCancel truncates the input while RecognizeAsyncStop doesn't. I'm guessing that calling both of them in a row is causing the error you're seeing.
Both RecognizeAsyncCancel and RecognizeAsyncStop have callbacks for when they are complete. You shouldn't do anything else with the engine until the final operation is complete. See the link for an example of how to do this.
Related
So, I'm trying to query cosmos collection for a specific document, with the following line of code:
FeedIterator<dynamic> querieditem = container.GetItemQueryIterator<dynamic>(mysqlquery);
When there exists an item in the database, this goes without any problems. However, when there doesn't exist any match in the database, I get the following exception:
System.Private.CoreLib: Exception while executing function: TestFunction. Microsoft.Azure.Cosmos.Client: Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId:123123; Reason: (Message: {"Errors":["Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"]}
Does this really mean, that I need to add a try/catch, in case GetItemQueryIterator() can't find anything in Cosmos? Given that it is necessary, why does this make sense?
Some of the methods in the SDK throw exceptions on 404 as a legacy holdover. The better alternative is to use the Stream variants of the methods, which don't throw and use HTTP status codes instead that can be used to evaluate success. You just need an extra step to deserialize the response stream yourself.
See the docs and examples for GetItemQueryStreamIterator
Note:
The point of this question is not to just getting back a value that I ultimately want.
I can do that by simply not using Optional.
I would like an elegant solution so I could start returning Optional.
Explanation of what I tried to do:
I used the QueryGateway with a signature that will query my handler.
I broke out my code so you can see that on my CompletableFuture I will do a blocking get in order to retrieve the Optional that contains the object I really want.
Note that I am not looking for a class that holds my optional.
If this is not elegant then I may as well just do my null check.
The call to the query works, but I get the following error:
org.axonframework.axonserver.connector.query.AxonServerQueryDispatchException: CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream
AXONIQ-5002
58484#DESKTOP-CK6HLMM
Example of code that initiates the query:
UserProfileOptionByUserQuery q = new UserProfileOptionByUserQuery(userId);
CompletableFuture<Optional<UserProfile>> query =
queryGateway.query(q,ResponseTypes.optionalInstanceOf(UserProfile.class));
Optional<UserProfile> optional = query.get();
Error occurs on the query.get() invocation.
Example of my Query Handler:
#QueryHandler
Optional<UserProfile> handle(UserProfileOptionByUserQuery query, #MetaDataValue(USER_INFO) UserInfo userInfo) {
assertUserCanQuery(query, userInfo);
return userProfileRepository.findById(query.getUserId());
}
The query handler works fine.
Other efforts such as using OptionalResponseType would not initiate my query as desired.
I think the key lies with the exception you are receiving Stephen.
Just to verify for my own good, I've tested the following permutations when it comes to Optional query handling:
Query Handler returns Optional, Query Dispatcher uses OptionalResponeType
Query Handler returns MyType, Query Dispatcher uses OptionalResponeType
Query Handler returns Optional, Query Dispatcher uses InstanceResponeType
Added, I've tried out these permutations both with the SimpleQueryBus and Axon Server. Both buses on all three options worked completely fine for me.
This suggest to me that you should dive in to the AxonServerQueryDispatchException you are receiving.
Hence, I am going to give you a couple of follow up questions to further deduce what the problem is. I'd suggest to update you original question with the response(s) to them.
Do you have a more detailed stack trace per chance?
And, what versions of Axon Framework and Axon Server are you using?
Are you on the Standard Edition? Enterprise edition?
Does this behavior only happen for this exact Optional query handler you've shared with us?
I'm writing automated tests for a Xamarin Forms mobile app. Since it's difficult to directly interact with an embedded Google/Apple map, I wrote a few backdoor methods designed to get all the information the map would provide to a human. However, on iOS, the method I wrote doesn't provide a return value, despite my instructions to the contrary.
So far, I've done all manner of things, including reducing the method to nothing but a stub returning a dummy string. It still refuses to do it. Nowhere in Microsoft's documentation indicates that a value can't be returned on iOS.
[Export("GetUnits:")]
public NSString GetUnits(NSString val) // param unused
{
return new NSString("TEST"); // returns this value in the app, but it doesn't ever make it to the test harness
}
The above code should return "TEST" to the test harness, which would then be printed in my REPL after I call app.Invoke("GetUnits:", ""), which always produces
[
]
instead of
[
"TEST"
]
The method is named properly and called properly; error messages occur if I don't call it properly (e.g. wrong number of parameters, wrong method name) and test code inserted into the method executes fine, so I know it's executing. It's just not returning the value to the test harness. The equivalent Android version of this method works perfectly.
I found one person on the Xamarin forums with the same problem, but his topic hasn't been touched in two years. I've read every pertinent thing I can find on the web, all to no avail.
Edited for formatting. (Whoops.)
Here's what we're using in our own integration tests to make sure we don't break this functionality:
This line is how we're calling the backdoor:
_app.Invoke("backdoorWithString:", stringArg).ToString().ShouldEqual(stringArg);
And in the app, the backdoor we're referencing is defined in a native app, so it's hard to compare:
- (NSString *) backdoorWithString:(NSString *) value {
I would advise changing your Export to the correct casing:
[Export("getUnits:")]
Also please check that this method is in your AppDelegate.cs file.
This question is related to direction provided to me in another post (see How can I stop a method using a Cancel button in visual C#?). My question, is whether there are any restrictions when creating a BackgroundWorker, as far as called methods are concerned? I have a method that executes fine outside the DoWork section of my BackgroundWorker, but the moment it is placed inside the DoWork, I get a Cross Thread error stating "Cross-thread operation not valid: Control "txtFileOutput" accessed from a thread other than the thread it was created on." I know the BackgroundWorker is working with a basic for loop and have validated that. The "txtFileOutput" control referenced in the error is a textbox, to which I'm piping output from a regex query against a file (this is the method I'm trying to call within the DoWork).
Background:
I have created a basic playground project that contains:
A testLogin.java file that contains:
a. testng package imports (org.testng.*)
b. selenium webdriver imports (org.openqa.selenium.*)
c. 5 test-methods with testng annotations:
#Test(groups={"init"})
public void openURL()
Contains webdriver code to initiate the webdriver and open a chrome >instance with a given url.
#Test(dependsOnGroups={"init"})
public void testLogin()
Contains webdriver code to:
1. Locate username password text-input elements, enter the username password from a properties file.
2. Locate the "log in" button and click the button to log-in
3. Manage a login-forcefully scenario if someone else has already logged in using the credentials.
#Test(dependsOnMethods={"testLogin"})
public void testPatientsScheduleList()
Contains webdriver code to check if any patients have been scheduled. If yes, then fetch the names and display in console.
#Test()
public void testLogout()
Contains webdriver code to locate the logout button and click on the button to logout of the app.
#AfterTest()
public void closeConnection()
Contains webdriver code to dispose the webdriver object and close the chrome instance.
Currently I am simply running the test script wrapped as testng methods from ANT and a testng-xslt report gets generated.
Issues:
1. Performing validations against every line of code of webdriver script in a test method:
I know:
1. Selenium webdriver script contains API methods (findElement() and others.) that throw exceptions as a result of a default assertion/validation they perform. These exceptions show up in the generated report when a test-method fails.
2. TestNG provides Assert class that has many assertion methods but I have not yet figured out how can i use them to perform validation/assertions against every line of code of webdriver script. I tried adding assertion methods after every line of webdriver script code. What appeared in the output was just an AssertionError exception for a testmethod.
2. Failing a certain test method which gets passed due to try.. catch block.
If I use a try catch block around a set of 2 or more test drive script steps, and if a test-case fails in any of the steps (script line) then the try..catch block handles it thereby showing the test-method as "passed" in the execution report, which actually failed.
3. Creating a custom report which will show desired test execution results and not stack-traces!
When I execute the above script, a testng-xslt report gets generated that contains pass/fail status of each test method in a test-suite (configured in testng.xml).
The test-results only give me whether a test-method has passed or failed and provides an exception's stack-trace which really doesn't provide any helpful information.
I don't want such abstract level of test execution results but something like:
Name | Started | Duration | What-really-went-wrong (Failure)
Can anyone please suggest/ give some pointers regarding:
1. How can I perform validation/assertion against every line of code of webdriver script in a test-method without writing asserts after every script line?
2. How can I fail a certain test method which gets passed due to try catch block?
3. How can I customize the failure reporting so that I can send a failure result like "Expected element "button" with id "bnt12" but did not find the element at step 3 of test-method" to testng's reporting utility?
4. In the testng-xslt report I want to display where exactly in the test-method a failure occurred. So for example if my test-method fails because of a webelement = driver.findElement() at line 3 of a test-method, I want to display this issue in the test-report in the "What-really-went-wrong" column. I have read about testng testlisteners TestListenerAdapter / ITestListener/ IReporter but I don't understand how to use them after checking testng's javadocs.
5. Also, I have to implement PageObject pattern once I am done with customizing the test report. Where would be the right place to perform assertions in a page-object pattern? Should assertions be written in the page object test methods or in the higher level test methods that will use the PageObject classes?
P.S: I am completely new to testng framework and webdriver scripting. Please bear with any technical mistakes or observation errors if any in the post.
How can I perform validation/assertion against every line of code of webdriver script in a test-method without writing asserts after
every script line?
I dont think so. It is the assertions that does the comparison. So u need it.
How can I fail a certain test method which gets passed due to try catch block?
try-catch will mask the assertion failure.(because on assertion failure, an assertion exception is thrown, so if your catch block is like (catch(Exception e)) Assertion failures wont escape the catch block.
How can I customize the failure reporting so that I can send a failure result like "Expected element "button" with id "bnt12" but did
not find the element at step 3 of test-method" to testng's reporting
utility?
You need to use test listeners . TestNG TestListenerAdapter is a good start
Also, I have to implement PageObject pattern once I am done with
customizing the test report. Where would be the right place to perform
assertions in a page-object pattern? Should assertions be written in
the page object test methods or in the higher level test methods that
will use the PageObject classes?
My personal choice is to use assertions in Test methods, since it is where we are doing the actual testing. Page objects contains scripts for navigating inside the web page.
How can I customize the failure reporting so that I can send a failure
result like "Expected element "button" with id "bnt12" but did not
find the element at step 3 of test-method" to testng's reporting
utility?
You can use extent report and testng listener class( in this class use onTestFailure method to customize your failure report).