forked from dCache/dcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: See GitHub issue dCache#7421 dCache#7421 Modification: An option to use json format was added. When it's set to true, BillingMessageSerializer is used to generate JSON output instead of text format. Further, if json format is set to true, there will be no header in the output file. Also some unit tests for json format were added. Result: Billing files can be written in json format. Acked-by: Tigran Patch: https://rb.dcache.org/r/14206/ Target: master Require-book: yes Require-notes: yes
- Loading branch information
Showing
5 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
modules/dcache/src/test/java/org/dcache/services/billing/text/BillingJsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.dcache.services.billing.text; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import diskCacheV111.util.PnfsId; | ||
import diskCacheV111.vehicles.DoorRequestInfoMessage; | ||
import diskCacheV111.vehicles.GenericStorageInfo; | ||
import diskCacheV111.vehicles.MoverInfoMessage; | ||
import diskCacheV111.vehicles.PoolHitInfoMessage; | ||
import diskCacheV111.vehicles.RemoveFileInfoMessage; | ||
import diskCacheV111.vehicles.StorageInfoMessage; | ||
import diskCacheV111.vehicles.WarningPnfsFileInfoMessage; | ||
import dmg.cells.nucleus.CellAddressCore; | ||
import java.nio.charset.StandardCharsets; | ||
import javax.security.auth.Subject; | ||
import org.dcache.mock.ProtocolInfoBuilder; | ||
import org.dcache.notification.BillingMessageSerializerVisitor; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
public class BillingJsonTest { | ||
|
||
private static final CellAddressCore cellAdressCore = new CellAddressCore( | ||
"bccs_uib_no_023@nas023_bccs_uib_no_1Domain"); | ||
private static final PnfsId pnfsid = new PnfsId("0000B706DD4045F346F2B90F882B706DA807"); | ||
private static final BillingMessageSerializerVisitor visitor = new BillingMessageSerializerVisitor(); | ||
GenericStorageInfo si = new GenericStorageInfo(); | ||
|
||
@Before | ||
public void setup() { | ||
si.setHsm("osm"); | ||
si.setStorageClass("atlas:default"); | ||
} | ||
|
||
@Test | ||
public void testDoorRequestInfoMessageValidJson() { | ||
DoorRequestInfoMessage msg = new DoorRequestInfoMessage(cellAdressCore); | ||
msg.setSubject(new Subject()); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testMoverInfoMessageValidJson() { | ||
MoverInfoMessage msg = new MoverInfoMessage(cellAdressCore, pnfsid); | ||
msg.setFileCreated(true); | ||
msg.setFileSize(687926); | ||
msg.setTransaction("remove"); | ||
msg.setSubject(new Subject()); | ||
msg.setStorageInfo(si); | ||
msg.setTransferAttributes(256437, 2784, | ||
ProtocolInfoBuilder.aProtocolInfo().withProtocol("GFtp") | ||
.withIPAddress("109.105.124.147").build()); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testPoolHitInfoMessageValidJson() { | ||
PoolHitInfoMessage msg = new PoolHitInfoMessage(cellAdressCore, pnfsid); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testRemoveFileInfoMessageValidJson() { | ||
RemoveFileInfoMessage msg = new RemoveFileInfoMessage(cellAdressCore, pnfsid); | ||
msg.setSubject(new Subject()); | ||
|
||
msg.setStorageInfo(si); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testStorageInfoMessageValidJson() { | ||
StorageInfoMessage msg = new StorageInfoMessage(cellAdressCore, pnfsid, true); | ||
msg.setStorageInfo(si); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testWarningPnfsFileInfoMessageValidJson() { | ||
WarningPnfsFileInfoMessage msg = new WarningPnfsFileInfoMessage("TODO", cellAdressCore, | ||
pnfsid, 0, "TODO"); | ||
|
||
msg.accept(visitor); | ||
|
||
assertTrue(isValidJson(new String(visitor.getData(), StandardCharsets.UTF_8))); | ||
} | ||
|
||
private boolean isValidJson(String string) { | ||
try { | ||
new JSONObject(string); | ||
return true; | ||
} catch (JSONException e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters