Yes, you can call batchable classes from schedulable classes. This is a very common use case.
As for testing you'll want to test them separately. Test methods for my schedulable classes that invoke a batchable class just verify that the batchable class is queued after the scheduled class has executed. I then have a separate test methods for my batch class that is queued for the test directly rather than through the schedulable class.
The reason behind this is the Test.stopTest() method only clears out queues (future, batch, scheduled) once. So you can have multiple future and batch calls run at that point, but if those cause any further queuing of processes they aren't run. Currently there isn't a way to flush the queues twice, just need to test them separately, which personnally I feel is a better and clearer testing scheme since it separates the various roles of each class better.
This will actually a bug in the code.
I can see this line -
System.enqueueJob(new SecondQueueableApex(counter));
I assume this is calling itself, due to which it starts getting into stack.
This will not be limitation of Queueable interface, but more about the how it is being called.
Current limit for number of such chained jobs can be 5. Check "Queueable Apex Limits" in this reference
If you can add the complete class of Queueable interface, I can check further if still facing issues.
Update 1
From comment -
Initially Sf added this limitation where you can have maximum of 2 Queueable jobs. This limitation has been removed now. I strongly feel that this is because of your org not having proper updated Queueable interface features. Try logging a case or trying on an org from different continent. So suppose if you are on ap1 POD, some how try on a org with different POD like eu1 or na1 etc
Do let me know if it helps .
Thanks,
Ray
Best Answer
You don't include any of your code, so am taking a bit of a stab here at answering your question. Normally, all
@future
and schedulable code runs when thetest.stopTest()
method is called. You should be able to query for your schedulable job in the chronTrigger object to find the number of times it's been run which allows you to assert that your job ran, plus assert the results of the code. The latter should also allow you to assert that the@future
method was called in the schedulable job.